mirror of
https://github.com/alexpasmantier/television.git
synced 2025-06-07 12:05:34 +00:00
feat(config): allow remapping input builtin keybindings (ctrl-e, ctrl-a, etc.)
This commit is contained in:
parent
3222037a02
commit
6bddf6be83
@ -206,8 +206,9 @@ impl App {
|
|||||||
> 0
|
> 0
|
||||||
{
|
{
|
||||||
for event in event_buf.drain(..) {
|
for event in event_buf.drain(..) {
|
||||||
let action = self.convert_event_to_action(event);
|
if let Some(action) = self.convert_event_to_action(event) {
|
||||||
action_tx.send(action)?;
|
action_tx.send(action)?;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let action_outcome = self.handle_actions(&mut action_buf).await?;
|
let action_outcome = self.handle_actions(&mut action_buf).await?;
|
||||||
@ -247,32 +248,27 @@ impl App {
|
|||||||
///
|
///
|
||||||
/// # Returns
|
/// # Returns
|
||||||
/// The action that corresponds to the given event.
|
/// The action that corresponds to the given event.
|
||||||
fn convert_event_to_action(&self, event: Event<Key>) -> Action {
|
fn convert_event_to_action(&self, event: Event<Key>) -> Option<Action> {
|
||||||
match event {
|
let action = match event {
|
||||||
Event::Input(keycode) => {
|
Event::Input(keycode) => {
|
||||||
info!("{:?}", keycode);
|
info!("{:?}", keycode);
|
||||||
// text input events
|
|
||||||
match keycode {
|
|
||||||
Key::Backspace => return Action::DeletePrevChar,
|
|
||||||
Key::Ctrl('w') => return Action::DeletePrevWord,
|
|
||||||
Key::Delete => return Action::DeleteNextChar,
|
|
||||||
Key::Left => return Action::GoToPrevChar,
|
|
||||||
Key::Right => return Action::GoToNextChar,
|
|
||||||
Key::Home | Key::Ctrl('a') => {
|
|
||||||
return Action::GoToInputStart
|
|
||||||
}
|
|
||||||
Key::End | Key::Ctrl('e') => return Action::GoToInputEnd,
|
|
||||||
Key::Char(c) => return Action::AddInputChar(c),
|
|
||||||
_ => {}
|
|
||||||
}
|
|
||||||
// get action based on keybindings
|
// get action based on keybindings
|
||||||
self.keymap.get(&keycode).cloned().unwrap_or(
|
if let Some(action) = self.keymap.get(&keycode) {
|
||||||
if let Key::Char(c) = keycode {
|
action.clone()
|
||||||
Action::AddInputChar(c)
|
} else {
|
||||||
} else {
|
// text input events
|
||||||
Action::NoOp
|
match keycode {
|
||||||
},
|
Key::Backspace => Action::DeletePrevChar,
|
||||||
)
|
Key::Ctrl('w') => Action::DeletePrevWord,
|
||||||
|
Key::Delete => Action::DeleteNextChar,
|
||||||
|
Key::Left => Action::GoToPrevChar,
|
||||||
|
Key::Right => Action::GoToNextChar,
|
||||||
|
Key::Home | Key::Ctrl('a') => Action::GoToInputStart,
|
||||||
|
Key::End | Key::Ctrl('e') => Action::GoToInputEnd,
|
||||||
|
Key::Char(c) => Action::AddInputChar(c),
|
||||||
|
_ => Action::NoOp,
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// terminal events
|
// terminal events
|
||||||
Event::Tick => Action::Tick,
|
Event::Tick => Action::Tick,
|
||||||
@ -280,6 +276,12 @@ impl App {
|
|||||||
Event::FocusGained => Action::Resume,
|
Event::FocusGained => Action::Resume,
|
||||||
Event::FocusLost => Action::Suspend,
|
Event::FocusLost => Action::Suspend,
|
||||||
Event::Closed => Action::NoOp,
|
Event::Closed => Action::NoOp,
|
||||||
|
};
|
||||||
|
|
||||||
|
if action == Action::NoOp {
|
||||||
|
None
|
||||||
|
} else {
|
||||||
|
Some(action)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user