mirror of
https://gitlab.com/gabmus/envision.git
synced 2025-09-15 14:02:01 +00:00
feat: small optimizations to log level enum
This commit is contained in:
parent
8d7c928ec3
commit
940d9c9dc8
1 changed files with 35 additions and 18 deletions
|
@ -1,3 +1,6 @@
|
||||||
|
use std::fmt::Display;
|
||||||
|
use std::slice::Iter;
|
||||||
|
|
||||||
use expect_dialog::ExpectDialog;
|
use expect_dialog::ExpectDialog;
|
||||||
use gtk::prelude::*;
|
use gtk::prelude::*;
|
||||||
use relm4::prelude::*;
|
use relm4::prelude::*;
|
||||||
|
@ -25,25 +28,29 @@ impl LogLevel {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn to_string(&self) -> &str {
|
pub fn iter() -> Iter<'static, LogLevel> {
|
||||||
match self {
|
[
|
||||||
|
Self::Trace,
|
||||||
|
Self::Debug,
|
||||||
|
Self::Info,
|
||||||
|
Self::Warning,
|
||||||
|
Self::Error,
|
||||||
|
]
|
||||||
|
.iter()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Display for LogLevel {
|
||||||
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
|
f.write_str(match self {
|
||||||
LogLevel::Trace => "Trace",
|
LogLevel::Trace => "Trace",
|
||||||
LogLevel::Debug => "Debug",
|
LogLevel::Debug => "Debug",
|
||||||
LogLevel::Info => "Info",
|
LogLevel::Info => "Info",
|
||||||
LogLevel::Warning => "Warning",
|
LogLevel::Warning => "Warning",
|
||||||
LogLevel::Error => "Error",
|
LogLevel::Error => "Error",
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
pub const DEBUG_LEVEL_STRINGS: [&str; 5] = ["Trace", "Debug", "Info", "Warning", "Error"];
|
|
||||||
pub const DEBUG_LEVEL_VALS: [LogLevel; 5] = [
|
|
||||||
LogLevel::Trace,
|
|
||||||
LogLevel::Debug,
|
|
||||||
LogLevel::Info,
|
|
||||||
LogLevel::Warning,
|
|
||||||
LogLevel::Error,
|
|
||||||
];
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum DebugViewMsg {
|
pub enum DebugViewMsg {
|
||||||
|
@ -100,7 +107,15 @@ impl SimpleComponent for DebugView {
|
||||||
set_icon_name: icon_name::LOUPE,
|
set_icon_name: icon_name::LOUPE,
|
||||||
set_tooltip_text: Some("Filter Log"),
|
set_tooltip_text: Some("Filter Log"),
|
||||||
},
|
},
|
||||||
pack_start: log_level_dropdown = >k::DropDown::from_strings(&DEBUG_LEVEL_STRINGS),
|
pack_start: log_level_dropdown = >k::DropDown::from_strings(
|
||||||
|
LogLevel::iter()
|
||||||
|
.map(|lvl| lvl.to_string())
|
||||||
|
.collect::<Vec<String>>()
|
||||||
|
.iter()
|
||||||
|
.map(|s| s.as_str())
|
||||||
|
.collect::<Vec<&str>>()
|
||||||
|
.as_slice()
|
||||||
|
),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
#[name(searchbar)]
|
#[name(searchbar)]
|
||||||
|
@ -141,17 +156,19 @@ impl SimpleComponent for DebugView {
|
||||||
let search_entry = self.search_entry.as_ref().unwrap().clone();
|
let search_entry = self.search_entry.as_ref().unwrap().clone();
|
||||||
let search_text = search_entry.text().to_string().trim().to_lowercase();
|
let search_text = search_entry.text().to_string().trim().to_lowercase();
|
||||||
// TODO: add log level filtering
|
// TODO: add log level filtering
|
||||||
let log_level = DEBUG_LEVEL_VALS
|
let log_level = LogLevel::iter()
|
||||||
|
.as_slice()
|
||||||
.get(self.dropdown.as_ref().unwrap().selected() as usize)
|
.get(self.dropdown.as_ref().unwrap().selected() as usize)
|
||||||
.unwrap_or(&LogLevel::Debug)
|
.unwrap();
|
||||||
.clone();
|
|
||||||
println!("log level: {}", log_level.to_string());
|
println!("log level: {}", log_level.to_string());
|
||||||
let log = match searchbar.is_search_mode() && !search_text.is_empty() {
|
let log = match searchbar.is_search_mode() && !search_text.is_empty() {
|
||||||
true => self.log
|
true => self
|
||||||
|
.log
|
||||||
.iter()
|
.iter()
|
||||||
.filter(|row| row.to_lowercase().contains(&search_text))
|
.filter(|row| row.to_lowercase().contains(&search_text))
|
||||||
.map(|s| s.to_string())
|
.map(|s| s.to_string())
|
||||||
.collect::<Vec<String>>().concat(),
|
.collect::<Vec<String>>()
|
||||||
|
.concat(),
|
||||||
false => self.log.concat(),
|
false => self.log.concat(),
|
||||||
};
|
};
|
||||||
self.textbuf.set_text(&log);
|
self.textbuf.set_text(&log);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue