ui debug in status line
This commit is contained in:
@@ -1,11 +1,12 @@
|
||||
// client/src/utils/debug_logger.rs
|
||||
use lazy_static::lazy_static;
|
||||
use std::collections::VecDeque; // <-- FIX: Import VecDeque
|
||||
use std::io;
|
||||
use std::sync::{Arc, Mutex};
|
||||
use std::sync::{Arc, Mutex}; // <-- FIX: Import Mutex
|
||||
|
||||
lazy_static! {
|
||||
static ref UI_DEBUG_BUFFER: Arc<Mutex<String>> =
|
||||
Arc::new(Mutex::new(String::from("Logger initialized...")));
|
||||
static ref UI_DEBUG_BUFFER: Arc<Mutex<VecDeque<(String, bool)>>> =
|
||||
Arc::new(Mutex::new(VecDeque::from([(String::from("Logger initialized..."), false)])));
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
@@ -23,15 +24,14 @@ impl UiDebugWriter {
|
||||
}
|
||||
}
|
||||
|
||||
// Implement the io::Write trait for our writer.
|
||||
// tracing_subscriber can use any type that implements `MakeWriter`.
|
||||
// A simple way to do this is to have our writer implement `io::Write`.
|
||||
impl io::Write for UiDebugWriter {
|
||||
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
|
||||
let mut buffer = UI_DEBUG_BUFFER.lock().unwrap();
|
||||
let message = String::from_utf8_lossy(buf);
|
||||
// We just want the latest message, trimmed of whitespace.
|
||||
*buffer = message.trim().to_string();
|
||||
let trimmed_message = message.trim().to_string();
|
||||
let is_error = trimmed_message.starts_with("ERROR");
|
||||
// Add the new message to the back of the queue
|
||||
buffer.push_back((trimmed_message, is_error));
|
||||
Ok(buf.len())
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ impl io::Write for UiDebugWriter {
|
||||
}
|
||||
}
|
||||
|
||||
// A public function to safely get the latest message from anywhere in the app.
|
||||
pub fn get_latest_debug_message() -> String {
|
||||
UI_DEBUG_BUFFER.lock().unwrap().clone()
|
||||
// A public function to pop the next message from the front of the queue.
|
||||
pub fn pop_next_debug_message() -> Option<(String, bool)> {
|
||||
UI_DEBUG_BUFFER.lock().unwrap().pop_front()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user