mirror of
https://github.com/veeso/termscp.git
synced 2025-12-07 09:36:00 -08:00
Redraw interface only if needed
This commit is contained in:
@@ -82,6 +82,7 @@ pub struct AuthActivity {
|
|||||||
input_mode: InputMode,
|
input_mode: InputMode,
|
||||||
popup_message: Option<String>,
|
popup_message: Option<String>,
|
||||||
password_placeholder: String,
|
password_placeholder: String,
|
||||||
|
redraw: bool, // Should ui actually be redrawned?
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AuthActivity {
|
impl AuthActivity {
|
||||||
@@ -102,6 +103,7 @@ impl AuthActivity {
|
|||||||
input_mode: InputMode::Text,
|
input_mode: InputMode::Text,
|
||||||
popup_message: None,
|
popup_message: None,
|
||||||
password_placeholder: String::new(),
|
password_placeholder: String::new(),
|
||||||
|
redraw: true, // True at startup
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -432,11 +434,16 @@ impl Activity for AuthActivity {
|
|||||||
}
|
}
|
||||||
// Start catching Input Events
|
// Start catching Input Events
|
||||||
if let Ok(input_events) = self.context.as_ref().unwrap().input_hnd.fetch_events() {
|
if let Ok(input_events) = self.context.as_ref().unwrap().input_hnd.fetch_events() {
|
||||||
|
if input_events.len() > 0 {
|
||||||
|
self.redraw = true; // Set redraw to true if there is at least one event
|
||||||
|
}
|
||||||
// Iterate over input events
|
// Iterate over input events
|
||||||
for event in input_events.iter() {
|
for event in input_events.iter() {
|
||||||
self.handle_input_event(event);
|
self.handle_input_event(event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Redraw if necessary
|
||||||
|
if self.redraw {
|
||||||
// Determine input mode
|
// Determine input mode
|
||||||
self.input_mode = self.select_input_mode();
|
self.input_mode = self.select_input_mode();
|
||||||
// draw interface
|
// draw interface
|
||||||
@@ -495,6 +502,9 @@ impl Activity for AuthActivity {
|
|||||||
});
|
});
|
||||||
// Reset ctx
|
// Reset ctx
|
||||||
self.context = Some(ctx);
|
self.context = Some(ctx);
|
||||||
|
// Set redraw to false
|
||||||
|
self.redraw = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// ### on_destroy
|
/// ### on_destroy
|
||||||
|
|||||||
@@ -2235,6 +2235,7 @@ impl Activity for FileTransferActivity {
|
|||||||
/// `on_draw` is the function which draws the graphical interface.
|
/// `on_draw` is the function which draws the graphical interface.
|
||||||
/// This function must be called at each tick to refresh the interface
|
/// This function must be called at each tick to refresh the interface
|
||||||
fn on_draw(&mut self) {
|
fn on_draw(&mut self) {
|
||||||
|
let mut redraw: bool = false; // Should ui actually be redrawned?
|
||||||
// Context must be something
|
// Context must be something
|
||||||
if self.context.is_none() {
|
if self.context.is_none() {
|
||||||
return;
|
return;
|
||||||
@@ -2254,17 +2255,24 @@ impl Activity for FileTransferActivity {
|
|||||||
self.draw();
|
self.draw();
|
||||||
// Connect to remote
|
// Connect to remote
|
||||||
self.connect();
|
self.connect();
|
||||||
|
// Redraw
|
||||||
|
redraw = true;
|
||||||
}
|
}
|
||||||
// Handle input events
|
// Handle input events
|
||||||
if let Ok(event) = self.context.as_ref().unwrap().input_hnd.read_event() {
|
if let Ok(event) = self.context.as_ref().unwrap().input_hnd.read_event() {
|
||||||
// Iterate over input events
|
// Iterate over input events
|
||||||
if let Some(event) = event {
|
if let Some(event) = event {
|
||||||
|
// Handle event
|
||||||
self.handle_input_event(&event);
|
self.handle_input_event(&event);
|
||||||
|
// Set redraw to true
|
||||||
|
redraw = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// @! draw interface
|
// @! draw interface
|
||||||
|
if redraw {
|
||||||
self.draw();
|
self.draw();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// ### on_destroy
|
/// ### on_destroy
|
||||||
///
|
///
|
||||||
|
|||||||
Reference in New Issue
Block a user