Better UI
This commit is contained in:
parent
ea2ec7a257
commit
e7946333ad
2 changed files with 22 additions and 12 deletions
|
|
@ -245,7 +245,7 @@ async fn client_read<T: AsyncRead + Unpin>(
|
||||||
info!("> Processing packets...");
|
info!("> Processing packets...");
|
||||||
loop {
|
loop {
|
||||||
let message = reader.read().await?;
|
let message = reader.read().await?;
|
||||||
info!("> packet {:?}", message);
|
// info!("> packet {:?}", message); // TODO: Smaller
|
||||||
|
|
||||||
use Message::*;
|
use Message::*;
|
||||||
match message {
|
match message {
|
||||||
|
|
|
||||||
32
src/ui.rs
32
src/ui.rs
|
|
@ -62,6 +62,7 @@ async fn run_ui_core(
|
||||||
execute!(stdout, EnterAlternateScreen, DisableLineWrap)?;
|
execute!(stdout, EnterAlternateScreen, DisableLineWrap)?;
|
||||||
let mut events = EventStream::new();
|
let mut events = EventStream::new();
|
||||||
|
|
||||||
|
let mut show_logs = false;
|
||||||
let mut lines: VecDeque<String> = VecDeque::with_capacity(1024);
|
let mut lines: VecDeque<String> = VecDeque::with_capacity(1024);
|
||||||
let mut ports = None;
|
let mut ports = None;
|
||||||
loop {
|
loop {
|
||||||
|
|
@ -72,6 +73,9 @@ async fn run_ui_core(
|
||||||
match ev {
|
match ev {
|
||||||
KeyEvent {code:KeyCode::Esc, ..} => { break; },
|
KeyEvent {code:KeyCode::Esc, ..} => { break; },
|
||||||
KeyEvent {code:KeyCode::Char('q'), ..} => { break; },
|
KeyEvent {code:KeyCode::Char('q'), ..} => { break; },
|
||||||
|
KeyEvent {code:KeyCode::Char('l'), ..} => {
|
||||||
|
show_logs = !show_logs;
|
||||||
|
}
|
||||||
_ => ()
|
_ => ()
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
@ -103,6 +107,7 @@ async fn run_ui_core(
|
||||||
|
|
||||||
queue!(stdout, Clear(ClearType::All), MoveTo(0, 0))?;
|
queue!(stdout, Clear(ClearType::All), MoveTo(0, 0))?;
|
||||||
|
|
||||||
|
// List of open ports
|
||||||
// How wide are all the things?
|
// How wide are all the things?
|
||||||
let columns: usize = columns.into();
|
let columns: usize = columns.into();
|
||||||
let padding = 1;
|
let padding = 1;
|
||||||
|
|
@ -123,7 +128,8 @@ async fn run_ui_core(
|
||||||
);
|
);
|
||||||
if let Some(ports) = &mut ports {
|
if let Some(ports) = &mut ports {
|
||||||
ports.sort_by(|a, b| a.port.partial_cmp(&b.port).unwrap());
|
ports.sort_by(|a, b| a.port.partial_cmp(&b.port).unwrap());
|
||||||
for port in ports.into_iter().take(((rows / 2) - 1).into()) {
|
let max_ports: usize = if show_logs { (rows / 2) - 1 } else { rows - 2 }.into();
|
||||||
|
for port in ports.into_iter().take(max_ports) {
|
||||||
print!(
|
print!(
|
||||||
" {:port_width$} {:url_width$} {:description_width$}\r\n",
|
" {:port_width$} {:url_width$} {:description_width$}\r\n",
|
||||||
port.port,
|
port.port,
|
||||||
|
|
@ -133,22 +139,26 @@ async fn run_ui_core(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let hr: usize = ((rows / 2) - 1).into();
|
// Log
|
||||||
let start: usize = if lines.len() > hr {
|
if show_logs {
|
||||||
lines.len() - hr
|
let hr: usize = ((rows / 2) - 2).into();
|
||||||
} else {
|
let start: usize = if lines.len() > hr {
|
||||||
0
|
lines.len() - hr
|
||||||
};
|
} else {
|
||||||
|
0
|
||||||
|
};
|
||||||
|
|
||||||
queue!(stdout, MoveTo(0, rows / 2))?;
|
queue!(stdout, MoveTo(0, rows / 2))?;
|
||||||
for line in lines.range(start..) {
|
print!("{}", format!("{:columns$}", " Log").negative());
|
||||||
print!("{}\r\n", line);
|
for line in lines.range(start..) {
|
||||||
|
print!("{}\r\n", line);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
queue!(stdout, MoveTo(0, rows - 1))?;
|
queue!(stdout, MoveTo(0, rows - 1))?;
|
||||||
print!(
|
print!(
|
||||||
"{}",
|
"{}",
|
||||||
format!("{:columns$}", " Press ESC or q to quit").negative()
|
format!("{:columns$}", " Press ESC or q to quit | l - toggle log").negative()
|
||||||
);
|
);
|
||||||
stdout.flush()?;
|
stdout.flush()?;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue