TUI Changes prep
This commit is contained in:
parent
e1bf152fdd
commit
e24b65833a
6 changed files with 42 additions and 7 deletions
36
src/gui/tui.rs
Normal file
36
src/gui/tui.rs
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
use sha1::digest::block_buffer::Lazy;
|
||||
use tokio::{self, sync::RwLock};
|
||||
|
||||
use crate::{gui::log_panel, main::SHUTDOWN};
|
||||
|
||||
// ****** UTIL ******
|
||||
fn init_terminal() {
|
||||
let mut stdout = stdout();
|
||||
execute!(stdout, EnterAlternateScreen).unwrap();
|
||||
enable_raw_mode().unwrap();
|
||||
}
|
||||
|
||||
// ****** MAIN ******
|
||||
pub static UNIQUE: Lazy<RwLock<bool>> = Lazy::new(|| RwLock::new(false));
|
||||
pub static TERMINAL: LazyLock<Arc<Mutex<Terminal<CrosstermBackend<Stdout>>>>> =
|
||||
LazyLock::new(|| {
|
||||
Arc::new(Mutex::new(
|
||||
Terminal::new(CrosstermBackend::new(stdout())).unwrap(),
|
||||
))
|
||||
});
|
||||
|
||||
pub fn start_tui() {
|
||||
tokio::spawn(async move {
|
||||
init_terminal();
|
||||
while !SHUTDOWN.read().await {
|
||||
if UNIQUE.read().await {
|
||||
render_tui();
|
||||
} else {
|
||||
thread::sleep(Duration::from_millis(50));
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
pub fn render_tui() {
|
||||
log_panel::render();
|
||||
}
|
||||
Loading…
Reference in a new issue