add logging-specific menu
This commit is contained in:
parent
7072055f38
commit
2a3eee895d
2 changed files with 46 additions and 23 deletions
|
@ -1,4 +1,9 @@
|
||||||
use std::{collections::BTreeMap, net::SocketAddr, sync::OnceLock, time::Duration};
|
use std::{
|
||||||
|
collections::BTreeMap,
|
||||||
|
net::SocketAddr,
|
||||||
|
sync::{LazyLock, OnceLock},
|
||||||
|
time::Duration,
|
||||||
|
};
|
||||||
|
|
||||||
use crossterm::event::{Event, EventStream, KeyCode, KeyEvent, KeyEventKind};
|
use crossterm::event::{Event, EventStream, KeyCode, KeyEvent, KeyEventKind};
|
||||||
use futures::{FutureExt, StreamExt};
|
use futures::{FutureExt, StreamExt};
|
||||||
|
@ -231,9 +236,37 @@ fn change_log_level(delta: isize) {
|
||||||
log::set_max_level(level);
|
log::set_max_level(level);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static MAIN_MENU: LazyLock<Line> = LazyLock::new(|| {
|
||||||
|
Line::from(vec![
|
||||||
|
" Send ".into(),
|
||||||
|
"<S>".blue().bold(),
|
||||||
|
" Receive ".into(),
|
||||||
|
"<R>".blue().bold(),
|
||||||
|
" Logs ".into(),
|
||||||
|
"<L>".blue().bold(),
|
||||||
|
" Previous Screen ".into(),
|
||||||
|
"<ESC>".blue().bold(),
|
||||||
|
" Quit ".into(),
|
||||||
|
"<Q>".blue().bold(),
|
||||||
|
])
|
||||||
|
});
|
||||||
|
|
||||||
|
static LOGGING_MENU: LazyLock<Line> = LazyLock::new(|| {
|
||||||
|
Line::from(vec![
|
||||||
|
" Reduce Logging Level ".into(),
|
||||||
|
"<LEFT>".blue().bold(),
|
||||||
|
" Increase Logging Level ".into(),
|
||||||
|
"<RIGHT>".blue().bold(),
|
||||||
|
" Previous Screen ".into(),
|
||||||
|
"<ESC>".blue().bold(),
|
||||||
|
" Quit ".into(),
|
||||||
|
"<Q>".blue().bold(),
|
||||||
|
])
|
||||||
|
});
|
||||||
|
|
||||||
impl Widget for &App {
|
impl Widget for &App {
|
||||||
fn render(self, area: Rect, buf: &mut Buffer) {
|
fn render(self, area: Rect, buf: &mut Buffer) {
|
||||||
let [top, middle, bottom] =
|
let [top, _middle, bottom] =
|
||||||
Layout::vertical([Constraint::Min(5), Constraint::Min(10), Constraint::Min(3)])
|
Layout::vertical([Constraint::Min(5), Constraint::Min(10), Constraint::Min(3)])
|
||||||
.split(area)
|
.split(area)
|
||||||
.as_array()
|
.as_array()
|
||||||
|
@ -247,7 +280,7 @@ impl Widget for &App {
|
||||||
.cloned()
|
.cloned()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let [header_left, header_right] =
|
let [_header_left, header_right] =
|
||||||
Layout::horizontal([Constraint::Percentage(50), Constraint::Percentage(50)])
|
Layout::horizontal([Constraint::Percentage(50), Constraint::Percentage(50)])
|
||||||
.split(top)
|
.split(top)
|
||||||
.as_array()
|
.as_array()
|
||||||
|
@ -257,21 +290,21 @@ impl Widget for &App {
|
||||||
let mode = self.screen.last().unwrap();
|
let mode = self.screen.last().unwrap();
|
||||||
match mode {
|
match mode {
|
||||||
CurrentScreen::Main => {
|
CurrentScreen::Main => {
|
||||||
main_page(*mode, area, buf);
|
main_page(*mode, &MAIN_MENU, area, buf);
|
||||||
logger(header_right.inner(Margin::new(1, 2)), buf);
|
logger(header_right.inner(Margin::new(1, 2)), buf);
|
||||||
let peers = PeersWidget { peers: &self.peers };
|
let peers = PeersWidget { peers: &self.peers };
|
||||||
peers.render(footer_right.inner(Margin::new(1, 1)), buf);
|
peers.render(footer_right.inner(Margin::new(1, 1)), buf);
|
||||||
NetworkInfoWidget.render(footer_left.inner(Margin::new(1, 1)), buf);
|
NetworkInfoWidget.render(footer_left.inner(Margin::new(1, 1)), buf);
|
||||||
}
|
}
|
||||||
CurrentScreen::Receiving => {
|
|
||||||
main_page(*mode, area, buf);
|
|
||||||
}
|
|
||||||
CurrentScreen::Logging => {
|
CurrentScreen::Logging => {
|
||||||
main_page(*mode, area, buf);
|
main_page(*mode, &LOGGING_MENU, area, buf);
|
||||||
logger(area.inner(Margin::new(2, 4)), buf);
|
logger(area.inner(Margin::new(2, 4)), buf);
|
||||||
}
|
}
|
||||||
|
CurrentScreen::Receiving => {
|
||||||
|
main_page(*mode, &MAIN_MENU, area, buf);
|
||||||
|
}
|
||||||
_ => {
|
_ => {
|
||||||
main_page(*mode, area, buf);
|
main_page(*mode, &MAIN_MENU, area, buf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -296,21 +329,11 @@ fn logger(area: Rect, buf: &mut Buffer) {
|
||||||
logger.render(area, buf);
|
logger.render(area, buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main_page(screen: CurrentScreen, area: Rect, buf: &mut Buffer) {
|
fn main_page(screen: CurrentScreen, menu: &Line, area: Rect, buf: &mut Buffer) {
|
||||||
let title = Line::from(" Joecalsend ".bold());
|
let title = Line::from(" Joecalsend ".bold());
|
||||||
let instructions = Line::from(vec![
|
|
||||||
" Send ".into(),
|
|
||||||
"<S>".blue().bold(),
|
|
||||||
" Receive ".into(),
|
|
||||||
"<R>".blue().bold(),
|
|
||||||
" Logs ".into(),
|
|
||||||
"<L>".blue().bold(),
|
|
||||||
" Quit ".into(),
|
|
||||||
"<Q> ".blue().bold(),
|
|
||||||
]);
|
|
||||||
let block = Block::bordered()
|
let block = Block::bordered()
|
||||||
.title(title.centered())
|
.title(title.centered())
|
||||||
.title_bottom(instructions.centered())
|
.title_bottom(menu.clone().centered())
|
||||||
.border_set(border::THICK);
|
.border_set(border::THICK);
|
||||||
|
|
||||||
let current_screen = format!("{screen:?}",);
|
let current_screen = format!("{screen:?}",);
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
use ratatui::{
|
use ratatui::{
|
||||||
buffer::Buffer,
|
buffer::Buffer,
|
||||||
layout::{Rect, Rows},
|
layout::Rect,
|
||||||
style::Stylize,
|
style::Stylize,
|
||||||
text::Line,
|
text::Line,
|
||||||
widgets::{Block, Borders, List, ListItem, Padding, Table, Widget},
|
widgets::{Block, Borders, List, ListItem, Padding, Widget},
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::Peers;
|
use super::Peers;
|
||||||
|
|
Loading…
Reference in a new issue