Added Basic Gui

This commit is contained in:
Jonathan Wanke 2025-09-05 01:43:47 +02:00
commit 226ac61cbb
6 changed files with 190 additions and 5 deletions

114
Cargo.lock generated
View file

@ -9,11 +9,14 @@ dependencies = [
"axum",
"bytes",
"cmake",
"color-eyre",
"crossterm",
"futures-util",
"json",
"ratatui",
"rustls",
"serde",
"sys-info",
"sysinfo",
"tokio",
"tokio-tungstenite",
@ -189,6 +192,33 @@ dependencies = [
"cc",
]
[[package]]
name = "color-eyre"
version = "0.6.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e5920befb47832a6d61ee3a3a846565cfa39b331331e68a3b1d1116630f2f26d"
dependencies = [
"backtrace",
"color-spantrace",
"eyre",
"indenter",
"once_cell",
"owo-colors",
"tracing-error",
]
[[package]]
name = "color-spantrace"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b8b88ea9df13354b55bc7234ebcce36e6ef896aca2e42a15de9e10edce01b427"
dependencies = [
"once_cell",
"owo-colors",
"tracing-core",
"tracing-error",
]
[[package]]
name = "compact_str"
version = "0.8.1"
@ -360,6 +390,16 @@ dependencies = [
"windows-sys 0.59.0",
]
[[package]]
name = "eyre"
version = "0.6.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7cd915d99f24784cdc19fd37ef22b97e3ff0ae756c7e492e9fbfe897d61e2aec"
dependencies = [
"indenter",
"once_cell",
]
[[package]]
name = "fnv"
version = "1.0.7"
@ -579,6 +619,12 @@ version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39"
[[package]]
name = "indenter"
version = "0.3.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "964de6e86d545b246d84badc0fef527924ace5134f30641c203ef52ba83f58d5"
[[package]]
name = "indoc"
version = "2.0.6"
@ -640,6 +686,12 @@ version = "0.12.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "078e285eafdfb6c4b434e0d31e8cfcb5115b651496faca5749b88fafd4f23bfd"
[[package]]
name = "lazy_static"
version = "1.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe"
[[package]]
name = "libc"
version = "0.2.175"
@ -755,6 +807,12 @@ version = "1.21.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d"
[[package]]
name = "owo-colors"
version = "4.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "48dd4f4a2c8405440fd0462561f0e5806bd0f77e86f51c761481bdd4018b545e"
[[package]]
name = "parking_lot"
version = "0.12.4"
@ -1080,6 +1138,15 @@ dependencies = [
"digest",
]
[[package]]
name = "sharded-slab"
version = "0.1.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f40ca3c46823713e0d4209592e8d6e826aa57e928f09752619fc696c499637f6"
dependencies = [
"lazy_static",
]
[[package]]
name = "shlex"
version = "1.3.0"
@ -1195,6 +1262,16 @@ version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0bf256ce5efdfa370213c1dabab5935a12e49f2c58d15e9eac2870d3b4f27263"
[[package]]
name = "sys-info"
version = "0.9.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0b3a0d0aba8bf96a0e1ddfdc352fc53b3df7f39318c71854910c3c4b024ae52c"
dependencies = [
"cc",
"libc",
]
[[package]]
name = "sysinfo"
version = "0.30.13"
@ -1230,6 +1307,15 @@ dependencies = [
"syn",
]
[[package]]
name = "thread_local"
version = "1.1.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f60246a4944f24f6e018aa17cdeffb7818b76356965d03b07d6a9886e8962185"
dependencies = [
"cfg-if",
]
[[package]]
name = "time"
version = "0.3.42"
@ -1354,6 +1440,28 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b9d12581f227e93f094d3af2ae690a574abb8a2b9b7a96e7cfe9647b2b617678"
dependencies = [
"once_cell",
"valuable",
]
[[package]]
name = "tracing-error"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8b1581020d7a273442f5b45074a6a57d5757ad0a47dac0e9f0bd57b81936f3db"
dependencies = [
"tracing",
"tracing-subscriber",
]
[[package]]
name = "tracing-subscriber"
version = "0.3.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2054a14f5307d601f88daf0553e1cbf472acc4f2c51afab632431cdcd72124d5"
dependencies = [
"sharded-slab",
"thread_local",
"tracing-core",
]
[[package]]
@ -1439,6 +1547,12 @@ dependencies = [
"wasm-bindgen",
]
[[package]]
name = "valuable"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ba73ea9cf16a25df0c8caa16c51acb937d5712a8429db78a3ee29d5dcacd3a65"
[[package]]
name = "version_check"
version = "0.9.5"

View file

@ -19,5 +19,8 @@ uuid = { version = "*", features = ["v4"] }
walkdir = "2.5.0"
sysinfo = "*"
serde = { version = "1.0.219", features = ["derive"] }
ratatui ={ version = "*", features = ["all-widgets"]}
ratatui = { version = "*", features = ["all-widgets"]}
bytes = "*"
crossterm = "*"
color-eyre = "*"
sys-info = "*"

View file

@ -0,0 +1 @@
pub mod ratatui_interface;

View file

@ -0,0 +1,57 @@
use color_eyre::Result;
use crossterm::event::{self, Event};
use ratatui::{DefaultTerminal, Frame};
use ratatui::widgets::{Block, Paragraph,};
use ratatui::layout::{Constraint, Layout, Direction};
use sys_info;
use crate::omikron::omikron_connection::OmikronConnection;
pub fn launch(connection_status: bool) -> Result<()> {
color_eyre::install()?;
let terminal = ratatui::init();
let result = run(terminal, connection_status);
ratatui::restore();
result
}
fn run(mut terminal: DefaultTerminal, connection_status: bool) -> Result<()> {
loop {
terminal.draw(|frame| render(frame, connection_status))?;
if matches!(event::read()?, Event::Key(_)) {
break Ok(());
}
}
}
fn render(frame: &mut Frame, connection_status: bool) {
let main_layout = Layout::default().direction(Direction::Horizontal).margin(1).constraints([Constraint::Percentage((100))].as_ref());
let main_block = Block::bordered().title("Tensamin - Iota");
let main_chunks = main_layout.split(frame.area());
let [left, right] = Layout::horizontal([Constraint::Fill(1); 2]).areas(main_chunks[0]);
let [top_right, bottom_right] = Layout::vertical([Constraint::Fill(1); 2]).areas(right);
let block_logs = Block::bordered().title("Logs");
let block_systeminfo = Block::bordered().title("System Info");
let block_ping = Block::bordered().title("Ping");
let mut operating_system: String;
match sys_info::os_type() {
Ok(os) => operating_system = os,
Err(error) => operating_system = error.to_string(),
}
let mut text_content: String = String::from("");
text_content.push_str("Operating System: ");
text_content.push_str(operating_system.as_str());
text_content.push_str("\nConnection: ");
text_content.push_str(if connection_status {"Connected"} else {"Disconnected"});
let paragraph_systeminfo = Paragraph::new(text_content).block(block_systeminfo);
frame.render_widget(Block::bordered().title("Tensamin - Iota"), frame.area());
frame.render_widget(Block::bordered().title("Logs"), left);
frame.render_widget(paragraph_systeminfo, top_right);
frame.render_widget(Block::bordered().title("Ping"), bottom_right);
}

View file

@ -6,13 +6,17 @@ mod data;
mod omikron;
mod util;
mod users;
mod gui {
pub mod ratatui_interface;
}
use crate::omikron::omikron_connection::{OmikronConnection};
use crate::data::communication::{CommunicationValue, CommunicationType, DataTypes};
use gui::{ratatui_interface};
fn main() {
let runtime: Runtime = tokio::runtime::Runtime::new().unwrap();
let omikron: OmikronConnection = OmikronConnection::new();
let mut omikron: OmikronConnection = OmikronConnection::new();
runtime.block_on(async {
omikron.connect().await;

View file

@ -22,10 +22,13 @@ use crate::{
data::communication::DataTypes
};
use crate::ratatui_interface;
#[derive(Clone)]
pub struct OmikronConnection {
writer: Arc<Mutex<Option<futures_util::stream::SplitSink<WebSocketStream<MaybeTlsStream<TcpStream>>, Message>>>>,
waiting: Arc<Mutex<HashMap<Uuid, Box<dyn Fn(String) + Send>>>>,
pub connected: bool,
}
impl OmikronConnection {
@ -33,14 +36,17 @@ impl OmikronConnection {
Self {
writer: Arc::new(Mutex::new(None)),
waiting: Arc::new(Mutex::new(HashMap::new())),
connected: bool::default(),
}
}
pub async fn connect(&self) {
pub async fn connect(&mut self) {
loop {
match connect_async("wss://tensamin.methanium.net/ws/iota/").await {
Ok((ws_stream, _)) => {
println!("[Omikron] Connected to server");
self.connected = true;
ratatui_interface::launch(self.connected);
// Split into writer + reader
let (write_half, read_half) = ws_stream.split();