UI-Loading Messages with more (Optional) Data
This commit is contained in:
parent
0d07ddf851
commit
a5ade7dd03
6 changed files with 114 additions and 38 deletions
|
|
@ -1,31 +1,32 @@
|
|||
use color_eyre::Result;
|
||||
use color_eyre::eyre::Error;
|
||||
use crossterm::event::{self, Event};
|
||||
use ratatui::layout::{Constraint, Direction, Layout};
|
||||
use ratatui::widgets::{Block, Paragraph};
|
||||
use ratatui::{DefaultTerminal, Frame};
|
||||
use ratatui::widgets::{Block, Paragraph,};
|
||||
use ratatui::layout::{Constraint, Layout, Direction};
|
||||
use sys_info;
|
||||
use tokio::task;
|
||||
|
||||
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);
|
||||
task::spawn(run(connection_status));
|
||||
ratatui::restore();
|
||||
result
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn run(mut terminal: DefaultTerminal, connection_status: bool) -> Result<()> {
|
||||
async fn run(connection_status: bool) -> Result<()> {
|
||||
loop {
|
||||
terminal.draw(|frame| render(frame, connection_status))?;
|
||||
if matches!(event::read()?, Event::Key(_)) {
|
||||
break Ok(());
|
||||
}
|
||||
ratatui::init().draw(|frame| render(frame, connection_status))?;
|
||||
}
|
||||
}
|
||||
|
||||
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_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());
|
||||
|
||||
|
|
@ -39,14 +40,18 @@ fn render(frame: &mut Frame, connection_status: bool) {
|
|||
let mut operating_system: String;
|
||||
match sys_info::os_type() {
|
||||
Ok(os) => operating_system = os,
|
||||
Err(error) => operating_system = error.to_string(),
|
||||
Err(error) => operating_system = error.to_string(),
|
||||
}
|
||||
|
||||
let mut text_content: String = String::from("");
|
||||
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"});
|
||||
text_content.push_str(if connection_status {
|
||||
"Connected"
|
||||
} else {
|
||||
"Disconnected"
|
||||
});
|
||||
|
||||
let paragraph_systeminfo = Paragraph::new(text_content).block(block_systeminfo);
|
||||
|
||||
|
|
@ -54,4 +59,4 @@ fn render(frame: &mut Frame, connection_status: bool) {
|
|||
frame.render_widget(Block::bordered().title("Logs"), left);
|
||||
frame.render_widget(paragraph_systeminfo, top_right);
|
||||
frame.render_widget(Block::bordered().title("Ping"), bottom_right);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue