mirror of
https://codeberg.org/unspeaker/perch.git
synced 2025-12-06 09:36:42 +01:00
wip: basic editing
This commit is contained in:
parent
b13ce4f0d0
commit
5336ee358a
4 changed files with 90 additions and 57 deletions
48
src/keys.rs
48
src/keys.rs
|
|
@ -2,6 +2,14 @@ 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)+,
|
||||
|
|
@ -9,7 +17,7 @@ macro_rules! press {
|
|||
modifiers: KeyModifiers::NONE,
|
||||
state: KeyEventState::NONE
|
||||
})
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
impl Handle<TuiIn> for Taggart {
|
||||
|
|
@ -17,24 +25,26 @@ impl Handle<TuiIn> for Taggart {
|
|||
let x_min = self.offset;
|
||||
let x_max = self.offset + self.size.h().saturating_sub(1);
|
||||
let event = &*input.event();
|
||||
match event {
|
||||
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.paths[self.cursor].path)?; }
|
||||
_ => match &self.editing {
|
||||
Some(_value) => match event {
|
||||
press!(Enter) => todo!(),
|
||||
press!(Esc) => todo!(),
|
||||
_ => {}
|
||||
},
|
||||
None => match event {
|
||||
press!(Enter) => todo!(),
|
||||
_ => {}
|
||||
}
|
||||
match &self.editing {
|
||||
Some(_value) => match event {
|
||||
press!(Char(c)) => self.edit_insert(*c),
|
||||
press!(Shift-Char(c)) => self.edit_insert(c.to_uppercase().next().unwrap()),
|
||||
press!(Backspace) => self.edit_backspace(),
|
||||
press!(Delete) => self.edit_delete(),
|
||||
press!(Enter) => self.edit_cancel(),
|
||||
press!(Esc) => self.edit_confirm(),
|
||||
_ => {}
|
||||
},
|
||||
None => match event {
|
||||
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.paths[self.cursor].path)?; }
|
||||
press!(Enter) => self.edit_begin(),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
if self.cursor < x_min {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue