added a little system resource monitor to the info pane, that shows CPU
usage and RAM usage and refresheds every second.
This commit is contained in:
@@ -14,6 +14,7 @@ use std::thread::spawn;
|
||||
use std::time::Duration;
|
||||
use std::{error::Error, time::Instant};
|
||||
use std::{io::Write, usize};
|
||||
use sysinfo::{MemoryRefreshKind, System};
|
||||
|
||||
pub fn get_user_input(prompt: &str) -> Result<String, Box<dyn Error>> {
|
||||
println!("{}", prompt);
|
||||
@@ -39,6 +40,10 @@ pub fn run_tui(
|
||||
let (event_tx, event_rx) = channel::<AppEvent>();
|
||||
let input_tx = event_tx.clone();
|
||||
let mut project_list_state = ListState::default();
|
||||
let mut system = System::new_all();
|
||||
let system_timer = Duration::from_secs(1);
|
||||
let mut last_print = Instant::now();
|
||||
const BYTES_PER_GB: u64 = 1024 * 1024 * 1024;
|
||||
if !state.projects.is_empty() {
|
||||
project_list_state.select(Some(0));
|
||||
state.selected_project = 0;
|
||||
@@ -82,6 +87,11 @@ pub fn run_tui(
|
||||
let mut history_index = state.history.len();
|
||||
let mut handles = Vec::new();
|
||||
loop {
|
||||
if Instant::now().duration_since(last_print) > system_timer {
|
||||
system.refresh_cpu_usage();
|
||||
system.refresh_memory();
|
||||
last_print = Instant::now();
|
||||
}
|
||||
let mut text_area_width = 0;
|
||||
terminal.draw(|f| {
|
||||
let main_chunks = Layout::default()
|
||||
@@ -118,6 +128,12 @@ pub fn run_tui(
|
||||
f.render_stateful_widget(projects_list, top_chunks[0], &mut project_list_state);
|
||||
let mut info_lines: Vec<Line> = Vec::new();
|
||||
let project = state.projects[state.selected_project].clone();
|
||||
info_lines.push(Line::from(format!(
|
||||
"|CPU: {}% | RAM: {}GB / {}GB |",
|
||||
system.global_cpu_usage().floor(),
|
||||
system.used_memory() / BYTES_PER_GB,
|
||||
system.total_memory() / BYTES_PER_GB,
|
||||
)));
|
||||
info_lines.push(Line::from(Span::styled(
|
||||
"--- PROJECT INFORMATION ---",
|
||||
Style::default().fg(Color::Green),
|
||||
|
||||
+14
-1
@@ -1815,7 +1815,7 @@ impl ModuleLoader {
|
||||
std::fs::write(path, contents).is_ok()
|
||||
});
|
||||
engine.register_fn("find_file", |path: PathBuf, filename: String| -> String {
|
||||
for entry in walkdir::WalkDir::new(path).max_depth(10) {
|
||||
for entry in walkdir::WalkDir::new(path).max_depth(50) {
|
||||
if let Ok(entry) = entry {
|
||||
if entry
|
||||
.file_name()
|
||||
@@ -1829,6 +1829,19 @@ impl ModuleLoader {
|
||||
|
||||
String::new()
|
||||
});
|
||||
engine.register_fn("execute", |cmd: &str| -> String {
|
||||
let out_string;
|
||||
if let Ok(output) = Command::new("sh").arg("-c").arg(cmd).output() {
|
||||
if output.status.success() {
|
||||
out_string = format!("[success] {}", String::from_utf8_lossy(&output.stdout));
|
||||
} else {
|
||||
out_string = format!("[error] {}", String::from_utf8_lossy(&output.stderr));
|
||||
}
|
||||
} else {
|
||||
out_string = "[error] failed to run command".to_string();
|
||||
}
|
||||
return out_string;
|
||||
});
|
||||
Self {
|
||||
engine: Arc::new(engine),
|
||||
commands: HashMap::new(),
|
||||
|
||||
Reference in New Issue
Block a user