mirror of
https://codeberg.org/icewind/logsmash.git
synced 2026-06-03 10:04:12 +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);
|
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) {
|
pub fn clear(&mut self) {
|
||||||
self.filter.clear();
|
self.filter.clear();
|
||||||
self.regex = None;
|
self.regex = None;
|
||||||
|
|
|
||||||
|
|
@ -35,16 +35,11 @@ impl StatefulWidget for GroupedLogs<'_> {
|
||||||
|
|
||||||
let par = Paragraph::new(format!(
|
let par = Paragraph::new(format!(
|
||||||
"{}{}{}\n\n{} from {} - Nextcloud {}",
|
"{}{}{}\n\n{} from {} - Nextcloud {}",
|
||||||
line
|
line.exception
|
||||||
.exception
|
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.map(|e| e.exception.as_ref())
|
.map(|e| e.exception.as_ref())
|
||||||
.unwrap_or_default(),
|
.unwrap_or_default(),
|
||||||
if line.exception.is_some() {
|
if line.exception.is_some() { ":\n" } else { "" },
|
||||||
":\n"
|
|
||||||
} else {
|
|
||||||
""
|
|
||||||
},
|
|
||||||
line.message,
|
line.message,
|
||||||
line.level.as_str(),
|
line.level.as_str(),
|
||||||
line.app,
|
line.app,
|
||||||
|
|
|
||||||
|
|
@ -8,8 +8,8 @@ use crate::ui::match_list::match_list;
|
||||||
use crate::ui::single_log::single_log;
|
use crate::ui::single_log::single_log;
|
||||||
use crate::ui::single_match::grouped_lines;
|
use crate::ui::single_match::grouped_lines;
|
||||||
use crate::ui::state::{
|
use crate::ui::state::{
|
||||||
ErrorState, GroupedLogsState, LogState, MatchListState, MatchState, Mode, UiEvent, UiPage,
|
ErrorState, GroupedLogsState, LogState, MatchListState, MatchState, Mode, PopMode, UiEvent,
|
||||||
UiState,
|
UiPage, UiState,
|
||||||
};
|
};
|
||||||
use ratatui::crossterm::event::{
|
use ratatui::crossterm::event::{
|
||||||
DisableMouseCapture, EnableMouseCapture, Event, KeyCode, KeyModifiers, MouseButton,
|
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::Esc) => Some(UiEvent::ClearFilter),
|
||||||
(Mode::FilterInput, KeyCode::F(4)) => Some(UiEvent::Back),
|
(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)),
|
(Mode::FilterInput, KeyCode::Char(c)) => Some(UiEvent::Text(c)),
|
||||||
_ => None,
|
_ => None,
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -429,9 +429,12 @@ impl<'a> UiState<'a> {
|
||||||
}
|
}
|
||||||
(true, ui)
|
(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() {
|
if let Some(filter) = ui.filter_mut() {
|
||||||
filter.pop();
|
match pop_mode {
|
||||||
|
PopMode::Character => filter.pop(),
|
||||||
|
PopMode::Word => filter.pop_word(),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
(true, ui)
|
(true, ui)
|
||||||
}
|
}
|
||||||
|
|
@ -493,7 +496,12 @@ pub enum UiEvent {
|
||||||
EnterFilterMode,
|
EnterFilterMode,
|
||||||
ClearFilter,
|
ClearFilter,
|
||||||
Text(char),
|
Text(char),
|
||||||
Backspace,
|
PopText(PopMode),
|
||||||
|
}
|
||||||
|
|
||||||
|
pub enum PopMode {
|
||||||
|
Character,
|
||||||
|
Word,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(PartialEq)]
|
#[derive(PartialEq)]
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue