mirror of
https://codeberg.org/unspeaker/perch.git
synced 2025-12-06 01:26:43 +01:00
59 lines
2.3 KiB
Rust
59 lines
2.3 KiB
Rust
use crate::*;
|
|
use opener::open;
|
|
|
|
macro_rules! press {
|
|
(Shift-$($key:tt)+) => {
|
|
Event::Key(KeyEvent {
|
|
code: KeyCode::$($key)+,
|
|
kind: KeyEventKind::Press,
|
|
modifiers: KeyModifiers::SHIFT,
|
|
state: KeyEventState::NONE
|
|
})
|
|
};
|
|
($($key:tt)+) => {
|
|
Event::Key(KeyEvent {
|
|
code: KeyCode::$($key)+,
|
|
kind: KeyEventKind::Press,
|
|
modifiers: KeyModifiers::NONE,
|
|
state: KeyEventState::NONE
|
|
})
|
|
};
|
|
}
|
|
|
|
mod edit;
|
|
mod save;
|
|
mod quit;
|
|
mod help;
|
|
|
|
impl Handle<TuiIn> for Taggart {
|
|
fn handle (&mut self, input: &TuiIn) -> Perhaps<bool> {
|
|
let min = self.offset;
|
|
let max = self.offset + self.display.h().saturating_sub(1);
|
|
let event = &*input.event();
|
|
match &self.mode {
|
|
Some(Mode::Edit { .. }) => self.handle_edit(event),
|
|
Some(Mode::Help { page }) => self.handle_help(event, *page),
|
|
Some(Mode::Save { choice }) => self.handle_save(event, *choice),
|
|
Some(Mode::Quit { choice }) => self.handle_quit(input, *choice),
|
|
None => match event {
|
|
press!(F(1)) => { self.help_begin() },
|
|
press!(Char('q')) => { self.quit_begin(&input) },
|
|
press!(Char('w')) => { self.save_begin() },
|
|
press!(Enter) => { self.edit_begin() },
|
|
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!(Char(' ')) => { open(self.entries[self.cursor].path.as_ref())?; }
|
|
press!(Char(']')) => { self.columns.0[self.column].width += 1; }
|
|
press!(Char('[')) => { self.columns.0[self.column].width =
|
|
self.columns.0[self.column].width.saturating_sub(1).max(5); }
|
|
_ => {}
|
|
},
|
|
}
|
|
self.clamp(min, max);
|
|
Ok(None)
|
|
}
|
|
}
|