mirror of
https://codeberg.org/unspeaker/perch.git
synced 2025-12-06 09:36:42 +01:00
dynamic columns; macro keydefs
This commit is contained in:
parent
b29511c23e
commit
8cc9418272
6 changed files with 113 additions and 147 deletions
95
src/keys.rs
95
src/keys.rs
|
|
@ -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)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue