mirror of
https://github.com/wez/wezterm.git
synced 2024-09-21 03:39:16 +03:00
termwiz: line editor: allow embedded app to override key map
This commit is contained in:
parent
e033e3576f
commit
eb1f583e2b
@ -23,4 +23,5 @@ pub enum Action {
|
||||
HistoryPrevious,
|
||||
HistoryNext,
|
||||
Complete,
|
||||
NoAction,
|
||||
}
|
||||
|
@ -1,4 +1,6 @@
|
||||
use crate::cell::{AttributeChange, CellAttributes};
|
||||
use crate::input::InputEvent;
|
||||
use crate::lineedit::actions::Action;
|
||||
use crate::lineedit::{BasicHistory, History};
|
||||
use crate::surface::Change;
|
||||
|
||||
@ -72,6 +74,17 @@ pub trait LineEditorHost {
|
||||
fn complete(&self, _line: &str, _cursor_position: usize) -> Vec<CompletionCandidate> {
|
||||
vec![]
|
||||
}
|
||||
|
||||
/// Allows the embedding application an opportunity to override or
|
||||
/// remap keys to alternative actions.
|
||||
/// Return `None` to indicate that the default keymap processing
|
||||
/// should occur.
|
||||
/// Otherwise return an `Action` enum variant indicating the action
|
||||
/// that should be taken.
|
||||
/// Use `Action::NoAction` to indicate that no action should be taken.
|
||||
fn resolve_action(&self, _event: &InputEvent) -> Option<Action> {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
/// A candidate for tab completion.
|
||||
|
@ -245,8 +245,11 @@ impl<T: Terminal> LineEditor<T> {
|
||||
self.terminal.set_cooked_mode()?;
|
||||
res
|
||||
}
|
||||
fn resolve_action(&self, event: &InputEvent, host: &mut dyn LineEditorHost) -> Option<Action> {
|
||||
if let Some(action) = host.resolve_action(event) {
|
||||
return Some(action);
|
||||
}
|
||||
|
||||
fn resolve_action(&self, event: &InputEvent) -> Option<Action> {
|
||||
match event {
|
||||
InputEvent::Key(KeyEvent {
|
||||
key: KeyCode::Char('C'),
|
||||
@ -534,8 +537,9 @@ impl<T: Terminal> LineEditor<T> {
|
||||
|
||||
self.render(host)?;
|
||||
while let Some(event) = self.terminal.poll_input(None)? {
|
||||
match self.resolve_action(&event) {
|
||||
match self.resolve_action(&event, host) {
|
||||
Some(Action::Cancel) => return Ok(None),
|
||||
Some(Action::NoAction) => {}
|
||||
Some(Action::AcceptLine) => break,
|
||||
Some(Action::EndOfFile) => {
|
||||
return Err(std::io::Error::new(
|
||||
|
Loading…
Reference in New Issue
Block a user