mirror of
https://codeberg.org/icewind/logsmash.git
synced 2026-06-03 18:14:11 +02:00
cleanup
This commit is contained in:
parent
483bb5691d
commit
a07deebbd6
3 changed files with 27 additions and 72 deletions
|
|
@ -30,6 +30,6 @@ pub fn footer(app: &App, page: UiPage) -> Table {
|
|||
fn help(page: UiPage) -> &'static str {
|
||||
match page {
|
||||
UiPage::MatchList => "«Q» Exit - «Enter» Select",
|
||||
UiPage::Match | UiPage::All | UiPage::Unmatched => "«Q» Exit - «Esc» Back",
|
||||
UiPage::Match => "«Q» Exit - «Esc» Back",
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -92,29 +92,13 @@ fn ui(frame: &mut Frame, app: &App, state: &mut UiState) {
|
|||
frame.render_widget(footer(app, page), layout[2]);
|
||||
}
|
||||
UiState::Match {
|
||||
selected: index,
|
||||
result,
|
||||
table_state,
|
||||
..
|
||||
} => {
|
||||
let log_match = &app.matches[*index];
|
||||
let selected_group = &log_match.grouped[table_state.selected().unwrap_or_default()];
|
||||
let selected_group = &result.grouped[table_state.selected().unwrap_or_default()];
|
||||
frame.render_widget(UiHistogram::new(&selected_group.histogram), layout[0]);
|
||||
frame.render_stateful_widget(grouped_lines(app, log_match), layout[1], table_state);
|
||||
frame.render_widget(footer(app, page), layout[2]);
|
||||
}
|
||||
UiState::All { table_state } => {
|
||||
let selected_group = &app.all.grouped[table_state.selected().unwrap_or_default()];
|
||||
frame.render_widget(UiHistogram::new(&selected_group.histogram), layout[0]);
|
||||
frame.render_stateful_widget(grouped_lines(app, &app.all), layout[1], table_state);
|
||||
frame.render_widget(footer(app, page), layout[2]);
|
||||
}
|
||||
UiState::Unmatched { table_state } => {
|
||||
let selected_group = &app.unmatched.grouped[table_state.selected().unwrap_or_default()];
|
||||
frame.render_widget(UiHistogram::new(&selected_group.histogram), layout[0]);
|
||||
frame.render_stateful_widget(
|
||||
grouped_lines(app, &app.unmatched),
|
||||
layout[1],
|
||||
table_state,
|
||||
);
|
||||
frame.render_stateful_widget(grouped_lines(app, result), layout[1], table_state);
|
||||
frame.render_widget(footer(app, page), layout[2]);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,26 +1,21 @@
|
|||
use crate::app::App;
|
||||
use crate::app::{App, LogMatch};
|
||||
use ratatui::widgets::TableState;
|
||||
use table_state::TableStateExt;
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub enum UiState {
|
||||
#[derive(Clone)]
|
||||
pub enum UiState<'a> {
|
||||
MatchList {
|
||||
table_state: TableState,
|
||||
},
|
||||
Match {
|
||||
selected: usize,
|
||||
table_state: TableState,
|
||||
},
|
||||
All {
|
||||
table_state: TableState,
|
||||
},
|
||||
Unmatched {
|
||||
result: &'a LogMatch,
|
||||
table_state: TableState,
|
||||
previous: Box<UiState<'a>>,
|
||||
},
|
||||
Quit,
|
||||
}
|
||||
|
||||
impl Default for UiState {
|
||||
impl Default for UiState<'_> {
|
||||
fn default() -> Self {
|
||||
let mut table_state = TableState::default();
|
||||
table_state.select(Some(0));
|
||||
|
|
@ -28,13 +23,11 @@ impl Default for UiState {
|
|||
}
|
||||
}
|
||||
|
||||
impl UiState {
|
||||
impl<'a> UiState<'a> {
|
||||
pub fn page(&self) -> UiPage {
|
||||
match self {
|
||||
UiState::Quit | UiState::MatchList { .. } => UiPage::MatchList,
|
||||
UiState::Match { .. } => UiPage::Match,
|
||||
UiState::All { .. } => UiPage::All,
|
||||
UiState::Unmatched { .. } => UiPage::Unmatched,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -42,8 +35,6 @@ impl UiState {
|
|||
match self {
|
||||
UiState::MatchList { table_state } => Some(table_state),
|
||||
UiState::Match { table_state, .. } => Some(table_state),
|
||||
UiState::All { table_state } => Some(table_state),
|
||||
UiState::Unmatched { table_state } => Some(table_state),
|
||||
UiState::Quit => None,
|
||||
}
|
||||
}
|
||||
|
|
@ -51,14 +42,12 @@ impl UiState {
|
|||
fn table_count(&self, app: &App) -> usize {
|
||||
match self {
|
||||
UiState::MatchList { .. } => app.match_lines(),
|
||||
UiState::Match { selected, .. } => app.matches[*selected].grouped.len(),
|
||||
UiState::All { .. } => app.all.grouped.len(),
|
||||
UiState::Unmatched { .. } => app.unmatched.grouped.len(),
|
||||
UiState::Match { result, .. } => result.grouped.len(),
|
||||
UiState::Quit => 0,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn process(self, event: UiEvent, app: &App) -> UiState {
|
||||
pub fn process(self, event: UiEvent, app: &'a App) -> UiState {
|
||||
match (self, event) {
|
||||
(UiState::Quit, _) => UiState::Quit,
|
||||
(_, UiEvent::Quit) => UiState::Quit,
|
||||
|
|
@ -77,41 +66,25 @@ impl UiState {
|
|||
}
|
||||
state
|
||||
}
|
||||
(UiState::MatchList { table_state }, UiEvent::Select) => {
|
||||
let selected = table_state.selected().unwrap_or(0);
|
||||
(mut prev @ UiState::MatchList { .. }, UiEvent::Select) => {
|
||||
let selected = prev.table_state().unwrap().selected().unwrap_or(0);
|
||||
let mut table_state = TableState::default();
|
||||
table_state.select(Some(0));
|
||||
if selected == 0 {
|
||||
UiState::All { table_state }
|
||||
|
||||
let result = if selected == 0 {
|
||||
&app.all
|
||||
} else if selected == app.match_lines() - 1 {
|
||||
UiState::Unmatched { table_state }
|
||||
&app.unmatched
|
||||
} else {
|
||||
UiState::Match {
|
||||
selected: selected - 1,
|
||||
table_state,
|
||||
}
|
||||
&app.matches[selected - 1]
|
||||
};
|
||||
UiState::Match {
|
||||
result,
|
||||
table_state,
|
||||
previous: Box::new(prev),
|
||||
}
|
||||
}
|
||||
(
|
||||
UiState::Match {
|
||||
selected: index, ..
|
||||
},
|
||||
UiEvent::Back,
|
||||
) => {
|
||||
let mut table_state = TableState::default();
|
||||
table_state.select(Some(index + 1));
|
||||
UiState::MatchList { table_state }
|
||||
}
|
||||
(UiState::All { .. }, UiEvent::Back) => {
|
||||
let mut table_state = TableState::default();
|
||||
table_state.select(Some(0));
|
||||
UiState::MatchList { table_state }
|
||||
}
|
||||
(UiState::Unmatched { .. }, UiEvent::Back) => {
|
||||
let mut table_state = TableState::default();
|
||||
table_state.select(Some(app.match_lines() - 1));
|
||||
UiState::MatchList { table_state }
|
||||
}
|
||||
(UiState::Match { previous, .. }, UiEvent::Back) => *previous,
|
||||
(state, _) => state,
|
||||
}
|
||||
}
|
||||
|
|
@ -128,8 +101,6 @@ pub enum UiEvent {
|
|||
pub enum UiPage {
|
||||
MatchList,
|
||||
Match,
|
||||
All,
|
||||
Unmatched,
|
||||
}
|
||||
|
||||
mod table_state {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue