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::{
|
use ratatui::{
|
||||||
DefaultTerminal, Frame,
|
DefaultTerminal, Frame,
|
||||||
buffer::Buffer,
|
buffer::Buffer,
|
||||||
layout::{Constraint, Direction, Layout, Margin, Rect},
|
layout::{Constraint, Layout, Margin, Rect},
|
||||||
style::{Style, Stylize},
|
style::{Style, Stylize},
|
||||||
symbols::border,
|
symbols::border,
|
||||||
text::{Line, Text},
|
text::{Line, Text},
|
||||||
|
@ -162,13 +162,22 @@ impl App {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn handle_key_event(&mut self, key_event: KeyEvent) {
|
fn handle_key_event(&mut self, key_event: KeyEvent) {
|
||||||
match key_event.code {
|
match self.screen.last().unwrap() {
|
||||||
KeyCode::Char('q') => self.exit(),
|
CurrentScreen::Logging => match key_event.code {
|
||||||
KeyCode::Char('s') => self.send(),
|
KeyCode::Esc => self.pop(),
|
||||||
KeyCode::Char('r') => self.recv(),
|
KeyCode::Left => change_log_level(-1),
|
||||||
KeyCode::Char('l') => self.logs(),
|
KeyCode::Right => change_log_level(1),
|
||||||
KeyCode::Esc => self.pop(),
|
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 {
|
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] =
|
||||||
|
@ -259,6 +293,7 @@ impl Widget for &App {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn logger(area: Rect, buf: &mut Buffer) {
|
fn logger(area: Rect, buf: &mut Buffer) {
|
||||||
|
let title = Line::from(log::max_level().as_str());
|
||||||
let logger = TuiLoggerWidget::default()
|
let logger = TuiLoggerWidget::default()
|
||||||
.output_separator('|')
|
.output_separator('|')
|
||||||
.output_timestamp(Some("%H:%M:%S%.3f".to_string()))
|
.output_timestamp(Some("%H:%M:%S%.3f".to_string()))
|
||||||
|
@ -266,7 +301,11 @@ fn logger(area: Rect, buf: &mut Buffer) {
|
||||||
.output_target(true)
|
.output_target(true)
|
||||||
.output_file(false)
|
.output_file(false)
|
||||||
.output_line(false)
|
.output_line(false)
|
||||||
.block(Block::bordered().border_set(border::THICK))
|
.block(
|
||||||
|
Block::bordered()
|
||||||
|
.border_set(border::THICK)
|
||||||
|
.title(title.centered()),
|
||||||
|
)
|
||||||
.style(Style::default())
|
.style(Style::default())
|
||||||
.state(&TuiWidgetState::new().set_default_display_level(LevelFilter::Debug));
|
.state(&TuiWidgetState::new().set_default_display_level(LevelFilter::Debug));
|
||||||
logger.render(area, buf);
|
logger.render(area, buf);
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
use ratatui::{
|
use ratatui::{
|
||||||
buffer::Buffer,
|
buffer::Buffer,
|
||||||
layout::Rect,
|
layout::{Rect, Rows},
|
||||||
style::Stylize,
|
style::Stylize,
|
||||||
text::Line,
|
text::Line,
|
||||||
widgets::{Block, Borders, List, ListItem, Padding, Widget},
|
widgets::{Block, Borders, List, ListItem, Padding, Table, Widget},
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::Peers;
|
use super::Peers;
|
||||||
|
@ -44,9 +44,13 @@ impl Widget for NetworkInfoWidget {
|
||||||
where
|
where
|
||||||
Self: Sized,
|
Self: Sized,
|
||||||
{
|
{
|
||||||
let udp: Line = format!("UDP socket:\t\t\t {:?}", joecalsend::LISTENING_SOCKET_ADDR)
|
// let rows = Rows::new(rect);
|
||||||
.yellow()
|
// let mut table = Table::default();
|
||||||
.into();
|
|
||||||
|
let udp = Line::default().spans(vec![
|
||||||
|
"UDP socket:".to_string().yellow(),
|
||||||
|
format!("{:?}", joecalsend::LISTENING_SOCKET_ADDR).yellow(),
|
||||||
|
]);
|
||||||
let multicast: Line = format!(
|
let multicast: Line = format!(
|
||||||
"Multicast address:\t\t {:?}:{}",
|
"Multicast address:\t\t {:?}:{}",
|
||||||
joecalsend::MULTICAST_IP,
|
joecalsend::MULTICAST_IP,
|
||||||
|
|
Loading…
Reference in a new issue