dynamic columns; macro keydefs

This commit is contained in:
🪞👃🪞 2025-03-09 04:11:07 +02:00
parent b29511c23e
commit 8cc9418272
6 changed files with 113 additions and 147 deletions

View file

@ -1,82 +1,29 @@
use crate::*;
macro_rules! press {
($key:tt) => {
Event::Key(KeyEvent {
code: KeyCode::$key,
kind: KeyEventKind::Press,
modifiers: KeyModifiers::NONE,
state: KeyEventState::NONE
})
}
}
impl Handle<TuiIn> for Taggart {
fn handle (&mut self, input: &TuiIn) -> Perhaps<bool> {
let x_min = self.offset;
let x_max = self.offset + self.size.h().saturating_sub(1);
match &*input.event() {
Event::Key(KeyEvent {
code: KeyCode::Up,
kind: KeyEventKind::Press,
modifiers: KeyModifiers::NONE,
state: KeyEventState::NONE
}) => {
self.cursor = self.cursor.saturating_sub(1);
},
Event::Key(KeyEvent {
code: KeyCode::Down,
kind: KeyEventKind::Press,
modifiers: KeyModifiers::NONE,
state: KeyEventState::NONE
}) => {
self.cursor = self.cursor + 1;
},
Event::Key(KeyEvent {
code: KeyCode::PageUp,
kind: KeyEventKind::Press,
modifiers: KeyModifiers::NONE,
state: KeyEventState::NONE
}) => {
self.cursor = self.cursor.saturating_sub(PAGE_SIZE);
},
Event::Key(KeyEvent {
code: KeyCode::PageDown,
kind: KeyEventKind::Press,
modifiers: KeyModifiers::NONE,
state: KeyEventState::NONE
}) => {
self.cursor += PAGE_SIZE;
},
Event::Key(KeyEvent {
code: KeyCode::Left,
kind: KeyEventKind::Press,
modifiers: KeyModifiers::NONE,
state: KeyEventState::NONE
}) => {
self.column = self.column.saturating_sub(1);
},
Event::Key(KeyEvent {
code: KeyCode::Right,
kind: KeyEventKind::Press,
modifiers: KeyModifiers::NONE,
state: KeyEventState::NONE
}) => {
self.column = self.column + 1;
},
Event::Key(KeyEvent {
code: KeyCode::Enter,
kind: KeyEventKind::Press,
modifiers: KeyModifiers::NONE,
state: KeyEventState::NONE
}) => {
self.editing = Some((self.cursor, self.column));
},
Event::Key(KeyEvent {
code: KeyCode::Esc,
kind: KeyEventKind::Press,
modifiers: KeyModifiers::NONE,
state: KeyEventState::NONE
}) => {
self.editing = None;
},
Event::Key(KeyEvent {
code: KeyCode::Tab,
kind: KeyEventKind::Press,
modifiers: KeyModifiers::NONE,
state: KeyEventState::NONE
}) => {
self.show_hash = !self.show_hash;
},
press!(Up) => { self.cursor = self.cursor.saturating_sub(1); },
press!(Down) => { self.cursor = self.cursor + 1; },
press!(PageUp) => { self.cursor = self.cursor.saturating_sub(PAGE_SIZE); },
press!(PageDown) => { self.cursor += PAGE_SIZE; },
press!(Left) => { self.column = self.column.saturating_sub(1); },
press!(Right) => { self.column = self.column + 1; },
press!(Enter) => { self.editing = Some((self.cursor, self.column)); },
press!(Esc) => { self.editing = None; },
_ => {}
}
if self.cursor < x_min {
@ -88,8 +35,8 @@ impl Handle<TuiIn> for Taggart {
if self.cursor >= self.paths.len() {
self.cursor = self.paths.len().saturating_sub(1)
}
if self.column + 1 > COLUMN_COUNT {
self.column = COLUMN_COUNT.saturating_sub(1)
if self.column + 1 > self.columns.0.len() {
self.column = self.columns.0.len().saturating_sub(1)
}
Ok(None)
}