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 futures::{FutureExt, StreamExt};
|
||||
|
@ -231,9 +236,37 @@ fn change_log_level(delta: isize) {
|
|||
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 {
|
||||
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)])
|
||||
.split(area)
|
||||
.as_array()
|
||||
|
@ -247,7 +280,7 @@ impl Widget for &App {
|
|||
.cloned()
|
||||
.unwrap();
|
||||
|
||||
let [header_left, header_right] =
|
||||
let [_header_left, header_right] =
|
||||
Layout::horizontal([Constraint::Percentage(50), Constraint::Percentage(50)])
|
||||
.split(top)
|
||||
.as_array()
|
||||
|
@ -257,21 +290,21 @@ impl Widget for &App {
|
|||
let mode = self.screen.last().unwrap();
|
||||
match mode {
|
||||
CurrentScreen::Main => {
|
||||
main_page(*mode, area, buf);
|
||||
main_page(*mode, &MAIN_MENU, area, buf);
|
||||
logger(header_right.inner(Margin::new(1, 2)), buf);
|
||||
let peers = PeersWidget { peers: &self.peers };
|
||||
peers.render(footer_right.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 => {
|
||||
main_page(*mode, area, buf);
|
||||
main_page(*mode, &LOGGING_MENU, area, 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);
|
||||
}
|
||||
|
||||
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 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()
|
||||
.title(title.centered())
|
||||
.title_bottom(instructions.centered())
|
||||
.title_bottom(menu.clone().centered())
|
||||
.border_set(border::THICK);
|
||||
|
||||
let current_screen = format!("{screen:?}",);
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
use ratatui::{
|
||||
buffer::Buffer,
|
||||
layout::{Rect, Rows},
|
||||
layout::Rect,
|
||||
style::Stylize,
|
||||
text::Line,
|
||||
widgets::{Block, Borders, List, ListItem, Padding, Table, Widget},
|
||||
widgets::{Block, Borders, List, ListItem, Padding, Widget},
|
||||
};
|
||||
|
||||
use super::Peers;
|
||||
|
|
Loading…
Reference in a new issue