diff --git a/src/app/model/filter.rs b/src/app/model/filter.rs index 2bb0ac7..26f65f6 100644 --- a/src/app/model/filter.rs +++ b/src/app/model/filter.rs @@ -1,16 +1,22 @@ use crossterm::event::{KeyCode, KeyEvent}; use ratatui::{ buffer::Buffer, - layout::Rect, + layout::{Position, Rect}, style::Styled, widgets::{Block, BorderType, Borders, Paragraph, Widget}, }; use crate::ui::constants::DEFAULT_STYLE; +#[derive(Clone)] +pub struct CursorState { + pub position: Position, +} + pub struct Filter { pub enabled: bool, pub prefix: Option, + pub cursor: CursorState, } impl Filter { @@ -18,6 +24,9 @@ impl Filter { Filter { enabled: false, prefix: None, + cursor: CursorState { + position: Position::default(), + }, } } @@ -59,6 +68,9 @@ impl Filter { _ => {} } } + pub fn cursor_position(&self) -> &Position { + &self.cursor.position + } } impl Default for Filter { @@ -67,11 +79,17 @@ impl Default for Filter { } } -impl Widget for &Filter { +impl Widget for &mut Filter { fn render(self, area: Rect, buf: &mut Buffer) { let filter = self.prefix().clone(); + let filter_text = filter.unwrap_or_default(); + + self.cursor.position = Position { + x: area.x + 1 + filter_text.len() as u16, + y: area.y + 1, + }; - let paragraph = Paragraph::new(filter.unwrap_or("".to_string())) + let paragraph = Paragraph::new(filter_text) .block( Block::default() .border_type(BorderType::Rounded) diff --git a/src/ui.rs b/src/ui.rs index 5679b06..b5f73dc 100644 --- a/src/ui.rs +++ b/src/ui.rs @@ -16,18 +16,32 @@ pub fn draw_ui(f: &mut Frame, app: &Arc>) { render_init_screen(f, app.ticks); return; } + // Only frame has the ability to set the cursor position, so we need to control the cursor filter from here + // Not very elegant, and quite some duplication... Should be refactored match app.active_panel { Panel::Config => { app.configs.render(f.area(), f.buffer_mut()); + if app.configs.filter.is_enabled() { + f.set_cursor_position(app.configs.filter.cursor.position); + } } Panel::Dag => { app.dags.render(f.area(), f.buffer_mut()); + if app.dags.filter.is_enabled() { + f.set_cursor_position(app.dags.filter.cursor.position); + } } Panel::DAGRun => { app.dagruns.render(f.area(), f.buffer_mut()); + if app.dagruns.filter.is_enabled() { + f.set_cursor_position(app.dagruns.filter.cursor.position); + } } Panel::TaskInstance => { app.task_instances.render(f.area(), f.buffer_mut()); + if app.task_instances.filter.is_enabled() { + f.set_cursor_position(app.task_instances.filter.cursor.position); + } } Panel::Logs => app.logs.render(f.area(), f.buffer_mut()), }