mirror of
https://github.com/veeso/termscp.git
synced 2025-12-07 09:36:00 -08:00
Working on activity refactoring
This commit is contained in:
@@ -25,9 +25,10 @@
|
||||
|
||||
// Sub modules
|
||||
mod bookmarks;
|
||||
mod callbacks;
|
||||
mod input;
|
||||
mod layout;
|
||||
mod callbacks; // REMOVE
|
||||
mod input; // REMOVE
|
||||
mod layout; // REMOVE
|
||||
mod update;
|
||||
|
||||
// Dependencies
|
||||
extern crate crossterm;
|
||||
@@ -40,6 +41,7 @@ use crate::filetransfer::FileTransferProtocol;
|
||||
use crate::system::bookmarks_client::BookmarksClient;
|
||||
use crate::system::config_client::ConfigClient;
|
||||
use crate::system::environment;
|
||||
use crate::ui::layout::view::View;
|
||||
use crate::utils::git;
|
||||
|
||||
// Includes
|
||||
@@ -51,6 +53,22 @@ use tui::style::Color;
|
||||
// Types
|
||||
type DialogCallback = fn(&mut AuthActivity);
|
||||
|
||||
// -- components
|
||||
const COMPONENT_TEXT_HEADER: &str = "TEXT_HEADER";
|
||||
const COMPONENT_TEXT_FOOTER: &str = "TEXT_FOOTER";
|
||||
const COMPONENT_TEXT_HELP: &str = "TEXT_HELP";
|
||||
const COMPONENT_TEXT_ERROR: &str = "TEXT_ERROR";
|
||||
const COMPONENT_INPUT_ADDR: &str = "INPUT_ADDRESS";
|
||||
const COMPONENT_INPUT_PORT: &str = "INPUT_PORT";
|
||||
const COMPONENT_INPUT_USERNAME: &str = "INPUT_USERNAME";
|
||||
const COMPONENT_INPUT_PASSWORD: &str = "INPUT_PASSWORD";
|
||||
const COMPONENT_INPUT_BOOKMARK_NAME: &str = "INPUT_BOOKMARK_NAME";
|
||||
const COMPONENT_RADIO_PROTOCOL: &str = "RADIO_PROTOCOL";
|
||||
const COMPONENT_RADIO_BOOKMARK_DEL: &str = "RADIO_DELETE_BOOKMARK";
|
||||
const COMPONENT_RADIO_BOOKMARK_SAVE_PWD: &str = "RADIO_SAVE_PASSWORD";
|
||||
const COMPONENT_BOOKMARKS_LIST: &str = "BOOKMARKS_LIST";
|
||||
const COMPONENT_RECENTS_LIST: &str = "RECENTS_LIST";
|
||||
|
||||
/// ### InputField
|
||||
///
|
||||
/// InputField describes the current input field to edit
|
||||
@@ -106,6 +124,7 @@ pub struct AuthActivity {
|
||||
pub quit: bool, // Becomes true if user has pressed esc
|
||||
pub setup: bool, // Becomes true if user has requested setup
|
||||
context: Option<Context>,
|
||||
view: View,
|
||||
bookmarks_client: Option<BookmarksClient>,
|
||||
config_client: Option<ConfigClient>,
|
||||
selected_field: InputField, // Selected field in AuthCredentials Form
|
||||
@@ -144,6 +163,7 @@ impl AuthActivity {
|
||||
quit: false,
|
||||
setup: false,
|
||||
context: None,
|
||||
view: View::init(),
|
||||
bookmarks_client: None,
|
||||
config_client: None,
|
||||
selected_field: InputField::Address,
|
||||
|
||||
72
src/ui/activities/auth_activity/update.rs
Normal file
72
src/ui/activities/auth_activity/update.rs
Normal file
@@ -0,0 +1,72 @@
|
||||
//! ## AuthActivity
|
||||
//!
|
||||
//! `auth_activity` is the module which implements the authentication activity
|
||||
|
||||
/*
|
||||
*
|
||||
* Copyright (C) 2020-2021 Christian Visintin - christian.visintin1997@gmail.com
|
||||
*
|
||||
* This file is part of "TermSCP"
|
||||
*
|
||||
* TermSCP is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* TermSCP is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with TermSCP. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
// locals
|
||||
use super::{
|
||||
AuthActivity, FileTransferProtocol, InputEvent,
|
||||
COMPONENT_TEXT_HELP
|
||||
};
|
||||
use crate::ui::layout::{Msg, Payload};
|
||||
// ext
|
||||
use crossterm::event::{KeyCode, KeyEvent, KeyModifiers};
|
||||
|
||||
// -- update
|
||||
|
||||
impl AuthActivity {
|
||||
|
||||
/// ### handle_input_event
|
||||
///
|
||||
/// Handle input event, based on current input mode
|
||||
pub(super) fn handle_input_event(&mut self, ev: InputEvent) {
|
||||
// Call update passing the return value from on
|
||||
self.update(self.view.on(ev));
|
||||
}
|
||||
|
||||
/// ### update
|
||||
///
|
||||
/// Update auth activity model based on msg
|
||||
/// The function exits when returns None
|
||||
pub(super) fn update(&mut self, msg: Option<(&str, Msg)>) -> Option<(&str, Msg)> {
|
||||
let key_enter = KeyEvent::from(KeyCode::Enter);
|
||||
// Match msg
|
||||
match msg {
|
||||
None => None, // Exit after None
|
||||
Some(msg) => match msg {
|
||||
(COMPONENT_TEXT_HELP, Msg::OnKey(key_enter) | (COMPONENT_TEXT_HELP, Msg::OnKey(KeyEvent::from(KeyCode::Esc))) => {
|
||||
// Hide text help
|
||||
match self.view.get_props(COMPONENT_TEXT_HELP) {
|
||||
None => None,
|
||||
Some(props) => self.update(self.view.update(COMPONENT_TEXT_HELP, props.hidden().build())),
|
||||
}
|
||||
}
|
||||
(_, Msg::OnSubmit(_)) | (_, Msg::OnKey(KeyEvent::from(KeyCode::Enter))) => {
|
||||
// Match <ENTER> key for all other components
|
||||
}
|
||||
(_, _) => None, // Ignore other events
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user