TUI Changes prep

This commit is contained in:
Alex Emmet 2025-11-25 16:14:37 +01:00
commit e24b65833a
6 changed files with 42 additions and 7 deletions

View file

@ -1 +0,0 @@

36
src/gui/tui.rs Normal file
View 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();
}

View file

@ -1 +0,0 @@

View file

@ -1,7 +1,9 @@
use json::{self, JsonValue::String};
use once_cell::sync::Lazy;
use std::sync::Arc;
use std::sync::LazyLock;
use std::sync::Mutex;
use tokio::sync::RwLock;
use tokio::time::{Duration, sleep};
use uuid::Uuid;
@ -34,6 +36,8 @@ use crate::util::file_util::has_dir;
pub static APP_STATE: LazyLock<Arc<Mutex<AppState>>> =
LazyLock::new(|| Arc::new(Mutex::new(AppState::new())));
pub static SHUTDOWN: Lazy<RwLock<bool>> = Lazy::new(|| RwLock::new(false));
#[tokio::main(flavor = "multi_thread", worker_threads = 8)]
#[allow(unused_must_use, dead_code)]
async fn main() {

View file

@ -8,9 +8,8 @@ use base64::engine::general_purpose::STANDARD;
use bytes::Bytes;
use futures::StreamExt;
use futures_util::TryFutureExt;
use http_body_util::BodyExt;
use http_body_util::Full;
use http_body_util::{BodyExt, Collected};
use hyper::upgrade::OnUpgrade;
use hyper::{Method, StatusCode};
use hyper::{
Request as HttpRequest, Response as HttpResponse, body::Incoming, server::conn::http1, upgrade,
@ -19,7 +18,6 @@ use hyper_util::rt::tokio::TokioIo;
use hyper_util::service::TowerToHyperService;
use rustls::ServerConfig;
use rustls::pki_types::{CertificateDer, PrivateKeyDer};
use sha1::digest::generic_array::arr::Inc;
use sha1::{Digest, Sha1};
use std::error::Error;
use std::io::ErrorKind;
@ -27,7 +25,6 @@ use std::io::{self, BufReader};
use std::net::{IpAddr, SocketAddr};
use std::result::Result::Ok;
use std::sync::Arc;
use std::thread::panicking;
use std::{future::Future, pin::Pin, time::Duration};
use tokio::net::TcpListener;
use tokio_rustls::TlsAcceptor;

View file

@ -1,6 +1,6 @@
use std::ffi::OsStr;
use std::fs::{self, File};
use std::io::{self, BufReader, Cursor, Read};
use std::io::{self, BufReader, Read};
use std::path::{Path, PathBuf};
use sysinfo::System;
use uuid::Uuid;