Skip to content

Commit

Permalink
Store fixed amount of lines
Browse files Browse the repository at this point in the history
  • Loading branch information
AS1100K committed Jan 15, 2025
1 parent f9808a3 commit 217ec7f
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions components/monitors/cu_consolemon/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,21 +293,28 @@ struct UI {
}

struct DebugLog {
debug_log: Mutex<String>,
debug_log: Mutex<Vec<String>>,
max_col: Mutex<u16>
}

impl DebugLog {
fn new() -> Self {
Self {
debug_log: Mutex::new(String::new()),
debug_log: Mutex::new(Vec::new()),
max_col: Mutex::new(100),
}
}

fn push_logs<A: AsRef<str>>(&self, logs: A) {
self.debug_log.lock().unwrap().push_str(logs.as_ref())
let mut log_lines = self.debug_log.lock().unwrap();
let max_col = *self.max_col.lock().unwrap();
log_lines.push(logs.as_ref().to_string());
if log_lines.len() > max_col as usize {
log_lines.remove(0);
}
}

fn get_logs(&self) -> std::sync::MutexGuard<'_, String> {
fn get_logs(&self) -> std::sync::MutexGuard<'_, Vec<String>> {
self.debug_log.lock().unwrap()
}
}
Expand Down Expand Up @@ -583,7 +590,7 @@ impl UI {
self.debug_output.push_logs(&error_buffer);
let debug_output = self.debug_output.get_logs();

let p = Paragraph::new(debug_output.as_str()).block(
let p = Paragraph::new(debug_output.join("")).block(
Block::default()
.title(" Debug Output ")
.borders(Borders::ALL),
Expand Down Expand Up @@ -693,6 +700,8 @@ impl UI {
}
_ => {}
}
} else if let Event::Resize(columns, _rows) = event::read()? {
*self.debug_output.max_col.lock().unwrap() = columns;
}
}
}
Expand Down

0 comments on commit 217ec7f

Please sign in to comment.