enable/disable raw mode

This commit is contained in:
ChristianVisintin
2020-11-23 16:59:30 +01:00
parent 589adf294f
commit 18db7f0305
3 changed files with 73 additions and 37 deletions

View File

@@ -31,6 +31,10 @@ use crate::host::Localhost;
use crate::ui::activities::{auth_activity::AuthActivity, auth_activity::ScpProtocol, Activity};
use crate::ui::context::Context;
// Namespaces
use std::thread::sleep;
use std::time::Duration;
/// ### NextActivity
///
/// NextActivity identified the next identity to run once the current has ended
@@ -56,13 +60,18 @@ struct FileTransferParams {
pub struct ActivityManager {
context: Context,
ftparams: Option<FileTransferParams>,
interval: Duration,
}
impl ActivityManager {
/// ### new
///
/// Initializes a new Activity Manager
pub fn new(client: Box<dyn FileTransfer>, local_dir: &PathBuf) -> Result<ActivityManager, ()> {
pub fn new(
client: Box<dyn FileTransfer>,
local_dir: &PathBuf,
interval: Duration,
) -> Result<ActivityManager, ()> {
// Prepare Context
let host: Localhost = match Localhost::new(local_dir.clone()) {
Ok(h) => h,
@@ -72,6 +81,7 @@ impl ActivityManager {
Ok(ActivityManager {
context: ctx,
ftparams: None,
interval: interval,
})
}
@@ -100,7 +110,52 @@ impl ActivityManager {
///
/// Loop for activity manager. You need to provide the activity to start with
/// Returns the exitcode
pub fn run(&mut self, launch_activity: NextActivity) -> i32 {
0
pub fn run(&mut self, launch_activity: NextActivity) {
let mut current_activity: Option<NextActivity> = Some(launch_activity);
loop {
current_activity = match current_activity {
Some(activity) => match activity {
NextActivity::Authentication => self.run_authentication(),
NextActivity::FileTransfer => self.run_authentication(), // FIXME: change
},
None => break, // Exit
}
}
}
// Loops
/// ### run_authentication
///
/// Loop for Authentication activity.
/// Returns when activity terminates.
/// Returns the next activity to run
fn run_authentication(&mut self) -> Option<NextActivity> {
// Prepare activity
let mut activity: AuthActivity = AuthActivity::new();
// Prepare result
let mut result: Option<NextActivity> = None;
// Create activity
activity.on_create(&mut self.context);
loop {
// Draw activity
activity.on_draw(&mut self.context);
// Check if has to be terminated
if activity.quit {
// Quit activities
result = None;
break;
}
if activity.submit {
// User submitted, set next activity
result = Some(NextActivity::FileTransfer);
break;
}
// Sleep for ticks
//sleep(self.interval);
}
// Destroy activity
activity.on_destroy(&mut self.context);
result
}
}