Optimizing log code

This commit is contained in:
ChristianVisintin
2020-12-19 21:05:56 +01:00
parent dd9f54acae
commit d95cda3dfc
2 changed files with 49 additions and 152 deletions

View File

@@ -19,7 +19,7 @@
*
*/
use super::{FileTransferActivity, InputField, InputMode, LogLevel, LogRecord, PopupType};
use super::{Color, FileTransferActivity, InputField, InputMode, LogLevel, LogRecord, PopupType};
impl FileTransferActivity {
/// ### log
@@ -38,6 +38,20 @@ impl FileTransferActivity {
self.log_index = 0;
}
/// ### log_and_alert
///
/// Add message to log events and also display it as an alert
pub(super) fn log_and_alert(&mut self, level: LogLevel, msg: String) {
// Set input mode
let color: Color = match level {
LogLevel::Error => Color::Red,
LogLevel::Info => Color::Green,
LogLevel::Warn => Color::Yellow,
};
self.log(level, msg.as_str());
self.input_mode = InputMode::Popup(PopupType::Alert(color, msg));
}
/// ### create_quit_popup
///
/// Create quit popup input mode (since must be shared between different input handlers)