change the log level in the log screen
This commit is contained in:
parent
9b2172aa3a
commit
7ecca3709d
2 changed files with 57 additions and 14 deletions
|
@ -12,7 +12,7 @@ use native_dialog::MessageDialogBuilder;
|
|||
use ratatui::{
|
||||
DefaultTerminal, Frame,
|
||||
buffer::Buffer,
|
||||
layout::{Constraint, Direction, Layout, Margin, Rect},
|
||||
layout::{Constraint, Layout, Margin, Rect},
|
||||
style::{Style, Stylize},
|
||||
symbols::border,
|
||||
text::{Line, Text},
|
||||
|
@ -162,13 +162,22 @@ impl App {
|
|||
}
|
||||
|
||||
fn handle_key_event(&mut self, key_event: KeyEvent) {
|
||||
match key_event.code {
|
||||
KeyCode::Char('q') => self.exit(),
|
||||
KeyCode::Char('s') => self.send(),
|
||||
KeyCode::Char('r') => self.recv(),
|
||||
KeyCode::Char('l') => self.logs(),
|
||||
KeyCode::Esc => self.pop(),
|
||||
_ => {}
|
||||
match self.screen.last().unwrap() {
|
||||
CurrentScreen::Logging => match key_event.code {
|
||||
KeyCode::Esc => self.pop(),
|
||||
KeyCode::Left => change_log_level(-1),
|
||||
KeyCode::Right => change_log_level(1),
|
||||
KeyCode::Char('q') => self.exit(),
|
||||
_ => {}
|
||||
},
|
||||
_ => match key_event.code {
|
||||
KeyCode::Char('q') => self.exit(),
|
||||
KeyCode::Char('s') => self.send(),
|
||||
KeyCode::Char('r') => self.recv(),
|
||||
KeyCode::Char('l') => self.logs(),
|
||||
KeyCode::Esc => self.pop(),
|
||||
_ => {}
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -212,6 +221,31 @@ impl App {
|
|||
}
|
||||
}
|
||||
|
||||
fn change_log_level(delta: i8) {
|
||||
let level = log::max_level();
|
||||
use LevelFilter::*;
|
||||
let nl = if delta.signum().is_positive() {
|
||||
match level {
|
||||
Off => Error,
|
||||
Error => Warn,
|
||||
Warn => Info,
|
||||
Info => Debug,
|
||||
Debug => Trace,
|
||||
Trace => Trace,
|
||||
}
|
||||
} else {
|
||||
match level {
|
||||
Off => Off,
|
||||
Error => Off,
|
||||
Warn => Error,
|
||||
Info => Warn,
|
||||
Debug => Info,
|
||||
Trace => Debug,
|
||||
}
|
||||
};
|
||||
log::set_max_level(nl);
|
||||
}
|
||||
|
||||
impl Widget for &App {
|
||||
fn render(self, area: Rect, buf: &mut Buffer) {
|
||||
let [top, middle, bottom] =
|
||||
|
@ -259,6 +293,7 @@ impl Widget for &App {
|
|||
}
|
||||
|
||||
fn logger(area: Rect, buf: &mut Buffer) {
|
||||
let title = Line::from(log::max_level().as_str());
|
||||
let logger = TuiLoggerWidget::default()
|
||||
.output_separator('|')
|
||||
.output_timestamp(Some("%H:%M:%S%.3f".to_string()))
|
||||
|
@ -266,7 +301,11 @@ fn logger(area: Rect, buf: &mut Buffer) {
|
|||
.output_target(true)
|
||||
.output_file(false)
|
||||
.output_line(false)
|
||||
.block(Block::bordered().border_set(border::THICK))
|
||||
.block(
|
||||
Block::bordered()
|
||||
.border_set(border::THICK)
|
||||
.title(title.centered()),
|
||||
)
|
||||
.style(Style::default())
|
||||
.state(&TuiWidgetState::new().set_default_display_level(LevelFilter::Debug));
|
||||
logger.render(area, buf);
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
use ratatui::{
|
||||
buffer::Buffer,
|
||||
layout::Rect,
|
||||
layout::{Rect, Rows},
|
||||
style::Stylize,
|
||||
text::Line,
|
||||
widgets::{Block, Borders, List, ListItem, Padding, Widget},
|
||||
widgets::{Block, Borders, List, ListItem, Padding, Table, Widget},
|
||||
};
|
||||
|
||||
use super::Peers;
|
||||
|
@ -44,9 +44,13 @@ impl Widget for NetworkInfoWidget {
|
|||
where
|
||||
Self: Sized,
|
||||
{
|
||||
let udp: Line = format!("UDP socket:\t\t\t {:?}", joecalsend::LISTENING_SOCKET_ADDR)
|
||||
.yellow()
|
||||
.into();
|
||||
// let rows = Rows::new(rect);
|
||||
// let mut table = Table::default();
|
||||
|
||||
let udp = Line::default().spans(vec![
|
||||
"UDP socket:".to_string().yellow(),
|
||||
format!("{:?}", joecalsend::LISTENING_SOCKET_ADDR).yellow(),
|
||||
]);
|
||||
let multicast: Line = format!(
|
||||
"Multicast address:\t\t {:?}:{}",
|
||||
joecalsend::MULTICAST_IP,
|
||||
|
|
Loading…
Reference in a new issue