This commit is contained in:
Jana Dönszelmann 2026-02-25 09:21:50 +01:00
parent d989f6e31e
commit cc4ecf40d7
No known key found for this signature in database
6 changed files with 402 additions and 331 deletions

View file

@ -32,27 +32,101 @@ impl Clone for LogView {
}
}
pub enum InputTarget {
Fields,
#[derive(Clone)]
pub enum FieldMatcher {
EqualTo,
Prefix(String),
Regex(String),
Contains(String),
}
impl FieldMatcher {
pub fn show(&self) -> String {
match self {
FieldMatcher::EqualTo => "equal to selected value".to_string(),
Self::Prefix(s) => format!("with a prefix of `{s}`"),
Self::Regex(s) => format!("matching /{s}/"),
Self::Contains(s) => format!("containing `{s}`"),
}
}
}
#[derive(Clone)]
pub enum InputTarget {
Fields(Option<FieldMatcher>),
Text(FieldMatcher),
This,
Surround,
}
impl InputTarget {
pub fn show(&self) -> String {
match self {
Self::Fields(None) => "logs with a field...".to_string(),
Self::Fields(Some(fm)) => format!("logs with the selected field {}", fm.show()),
Self::Text(fm) => format!("logs {}", fm.show()),
Self::This => format!("this log"),
Self::Surround => format!("the log surrounding the current view"),
}
}
}
#[derive(Clone)]
pub enum InputState {
None,
Target(InputTarget),
}
impl InputState {
pub fn capture_string(&mut self) -> Option<&mut String> {
match self {
InputState::None => None,
InputState::Target(InputTarget::This) => None,
InputState::Target(InputTarget::Fields(None)) => None,
InputState::Target(InputTarget::Surround) => None,
// require arbitrary text input
InputState::Target(InputTarget::Fields(Some(FieldMatcher::Contains(s)))) => Some(s),
InputState::Target(InputTarget::Text(FieldMatcher::Contains(s))) => Some(s),
InputState::Target(InputTarget::Fields(Some(FieldMatcher::Prefix(s)))) => Some(s),
InputState::Target(InputTarget::Text(FieldMatcher::Prefix(s))) => Some(s),
InputState::Target(InputTarget::Fields(Some(FieldMatcher::Regex(s)))) => Some(s),
InputState::Target(InputTarget::Text(FieldMatcher::Regex(s))) => Some(s),
InputState::Target(InputTarget::Fields(Some(FieldMatcher::EqualTo))) => None,
InputState::Target(InputTarget::Text(FieldMatcher::EqualTo)) => None,
}
}
pub fn captures_input(&mut self) -> bool {
self.capture_string().is_some()
}
pub fn show(&self) -> String {
match self {
InputState::None => "".to_string(),
InputState::Target(input_target) => input_target.show(),
}
}
pub fn reset(&mut self) {
*self = Self::None;
}
pub fn target(&mut self, target: InputTarget) {
*self = Self::Target(target);
if let Self::Target(t) = self
&& mem::discriminant(t) == mem::discriminant(&target)
&& !self.captures_input()
{
self.reset();
} else {
*self = Self::Target(target);
}
}
}
pub struct LogViewer {
stack: Vec<LogView>,
pub stack: Vec<LogView>,
curr: LogView,
cache: HashMap<Vec<usize>, LogView>,
filters: Vec<Rc<Filter>>,
@ -253,9 +327,10 @@ impl LogViewer {
self.curr.selection_offset -= 1;
}
}
InputState::Target(InputTarget::Fields) => {
InputState::Target(InputTarget::Fields(None)) => {
self.footer_list.previous();
}
_ => {}
}
}
@ -264,9 +339,10 @@ impl LogViewer {
InputState::None => {
self.curr.selection_offset += 1;
}
InputState::Target(InputTarget::Fields) => {
InputState::Target(InputTarget::Fields(None)) => {
self.footer_list.next();
}
_ => {}
}
}
@ -292,9 +368,10 @@ impl LogViewer {
self.curr.selection_offset = 0;
while self.curr.iter.prev().is_some() {}
}
InputState::Target(InputTarget::Fields) => {
InputState::Target(InputTarget::Fields(None)) => {
self.footer_list.select(Some(0));
}
_ => {}
}
}
@ -331,9 +408,10 @@ impl LogViewer {
self.curr = cached_view.clone();
}
}
InputState::Target(InputTarget::Fields) => {
InputState::Target(InputTarget::Fields(None)) => {
self.footer_list.next();
}
_ => {}
}
}
}