mirror of
https://codeberg.org/icewind/logsmash.git
synced 2026-06-03 18:14:11 +02:00
implement Ctrl+W in filter input
This commit is contained in:
parent
4d9719345f
commit
14e5ea72b0
4 changed files with 30 additions and 13 deletions
|
|
@ -211,6 +211,13 @@ impl Filter {
|
|||
self.regex = Self::build_regex(&self.filter);
|
||||
}
|
||||
|
||||
pub fn pop_word(&mut self) {
|
||||
let previous_word_boundary = self.filter.trim().rfind(' ').map(|i| i + 1);
|
||||
self.filter
|
||||
.truncate(previous_word_boundary.unwrap_or_default());
|
||||
self.regex = Self::build_regex(&self.filter);
|
||||
}
|
||||
|
||||
pub fn clear(&mut self) {
|
||||
self.filter.clear();
|
||||
self.regex = None;
|
||||
|
|
|
|||
|
|
@ -35,16 +35,11 @@ impl StatefulWidget for GroupedLogs<'_> {
|
|||
|
||||
let par = Paragraph::new(format!(
|
||||
"{}{}{}\n\n{} from {} - Nextcloud {}",
|
||||
line
|
||||
.exception
|
||||
line.exception
|
||||
.as_ref()
|
||||
.map(|e| e.exception.as_ref())
|
||||
.unwrap_or_default(),
|
||||
if line.exception.is_some() {
|
||||
":\n"
|
||||
} else {
|
||||
""
|
||||
},
|
||||
if line.exception.is_some() { ":\n" } else { "" },
|
||||
line.message,
|
||||
line.level.as_str(),
|
||||
line.app,
|
||||
|
|
|
|||
|
|
@ -8,8 +8,8 @@ use crate::ui::match_list::match_list;
|
|||
use crate::ui::single_log::single_log;
|
||||
use crate::ui::single_match::grouped_lines;
|
||||
use crate::ui::state::{
|
||||
ErrorState, GroupedLogsState, LogState, MatchListState, MatchState, Mode, UiEvent, UiPage,
|
||||
UiState,
|
||||
ErrorState, GroupedLogsState, LogState, MatchListState, MatchState, Mode, PopMode, UiEvent,
|
||||
UiPage, UiState,
|
||||
};
|
||||
use ratatui::crossterm::event::{
|
||||
DisableMouseCapture, EnableMouseCapture, Event, KeyCode, KeyModifiers, MouseButton,
|
||||
|
|
@ -110,7 +110,14 @@ fn handle_events(page: UiPage, ui_state: &UiState) -> io::Result<Option<UiEvent>
|
|||
|
||||
(Mode::FilterInput, KeyCode::Esc) => Some(UiEvent::ClearFilter),
|
||||
(Mode::FilterInput, KeyCode::F(4)) => Some(UiEvent::Back),
|
||||
(Mode::FilterInput, KeyCode::Backspace) => Some(UiEvent::Backspace),
|
||||
(Mode::FilterInput, KeyCode::Backspace) => {
|
||||
Some(UiEvent::PopText(PopMode::Character))
|
||||
}
|
||||
(Mode::FilterInput, KeyCode::Char('w'))
|
||||
if key.modifiers == KeyModifiers::CONTROL =>
|
||||
{
|
||||
Some(UiEvent::PopText(PopMode::Word))
|
||||
}
|
||||
(Mode::FilterInput, KeyCode::Char(c)) => Some(UiEvent::Text(c)),
|
||||
_ => None,
|
||||
});
|
||||
|
|
|
|||
|
|
@ -429,9 +429,12 @@ impl<'a> UiState<'a> {
|
|||
}
|
||||
(true, ui)
|
||||
}
|
||||
(mut ui, UiEvent::Backspace) if ui.mode() == Mode::FilterInput => {
|
||||
(mut ui, UiEvent::PopText(pop_mode)) if ui.mode() == Mode::FilterInput => {
|
||||
if let Some(filter) = ui.filter_mut() {
|
||||
filter.pop();
|
||||
match pop_mode {
|
||||
PopMode::Character => filter.pop(),
|
||||
PopMode::Word => filter.pop_word(),
|
||||
}
|
||||
}
|
||||
(true, ui)
|
||||
}
|
||||
|
|
@ -493,7 +496,12 @@ pub enum UiEvent {
|
|||
EnterFilterMode,
|
||||
ClearFilter,
|
||||
Text(char),
|
||||
Backspace,
|
||||
PopText(PopMode),
|
||||
}
|
||||
|
||||
pub enum PopMode {
|
||||
Character,
|
||||
Word,
|
||||
}
|
||||
|
||||
#[derive(PartialEq)]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue