Skip to content

Commit

Permalink
terminal: Add Alt key bindings for terminal (#14556)
Browse files Browse the repository at this point in the history
- Makes using emacs-style alt/option/meta key shortcuts work in terminal (e.g. `M-%`)
- Fixes: #14543 

Co-authored-by: Peter Tripp <[email protected]>
  • Loading branch information
CharlesChen0823 and notpeter authored Jul 28, 2024
1 parent d6bdaa8 commit 66ada3e
Showing 1 changed file with 97 additions and 0 deletions.
97 changes: 97 additions & 0 deletions crates/terminal/src/mappings/keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,103 @@ pub fn to_esc_str(keystroke: &Keystroke, mode: &TermMode, alt_is_meta: bool) ->
("^", AlacModifiers::Ctrl) => Some("\x1e".to_string()), //30
("_", AlacModifiers::Ctrl) => Some("\x1f".to_string()), //31
("?", AlacModifiers::Ctrl) => Some("\x7f".to_string()), //127
// Mapping of Alt+key; emacs meta key: M-
("a", AlacModifiers::Alt) => Some("\x1ba".to_string()),
("A", AlacModifiers::Alt) => Some("\x1bA".to_string()),
("b", AlacModifiers::Alt) => Some("\x1bb".to_string()),
("B", AlacModifiers::Alt) => Some("\x1bB".to_string()),
("c", AlacModifiers::Alt) => Some("\x1bc".to_string()),
("C", AlacModifiers::Alt) => Some("\x1bC".to_string()),
("d", AlacModifiers::Alt) => Some("\x1bd".to_string()),
("D", AlacModifiers::Alt) => Some("\x1bD".to_string()),
("e", AlacModifiers::Alt) => Some("\x1be".to_string()),
("E", AlacModifiers::Alt) => Some("\x1bE".to_string()),
("f", AlacModifiers::Alt) => Some("\x1bf".to_string()),
("F", AlacModifiers::Alt) => Some("\x1bF".to_string()),
("g", AlacModifiers::Alt) => Some("\x1bg".to_string()),
("G", AlacModifiers::Alt) => Some("\x1bG".to_string()),
("h", AlacModifiers::Alt) => Some("\x1bh".to_string()),
("H", AlacModifiers::Alt) => Some("\x1bH".to_string()),
("i", AlacModifiers::Alt) => Some("\x1bi".to_string()),
("I", AlacModifiers::Alt) => Some("\x1bI".to_string()),
("j", AlacModifiers::Alt) => Some("\x1bj".to_string()),
("J", AlacModifiers::Alt) => Some("\x1bJ".to_string()),
("k", AlacModifiers::Alt) => Some("\x1bk".to_string()),
("K", AlacModifiers::Alt) => Some("\x1bK".to_string()),
("l", AlacModifiers::Alt) => Some("\x1bl".to_string()),
("L", AlacModifiers::Alt) => Some("\x1bL".to_string()),
("m", AlacModifiers::Alt) => Some("\x1bm".to_string()),
("M", AlacModifiers::Alt) => Some("\x1bM".to_string()),
("n", AlacModifiers::Alt) => Some("\x1bn".to_string()),
("N", AlacModifiers::Alt) => Some("\x1bN".to_string()),
("o", AlacModifiers::Alt) => Some("\x1bo".to_string()),
("O", AlacModifiers::Alt) => Some("\x1bO".to_string()),
("p", AlacModifiers::Alt) => Some("\x1bp".to_string()),
("P", AlacModifiers::Alt) => Some("\x1bP".to_string()),
("q", AlacModifiers::Alt) => Some("\x1bq".to_string()),
("Q", AlacModifiers::Alt) => Some("\x1bQ".to_string()),
("r", AlacModifiers::Alt) => Some("\x1br".to_string()),
("R", AlacModifiers::Alt) => Some("\x1bR".to_string()),
("s", AlacModifiers::Alt) => Some("\x1bs".to_string()),
("S", AlacModifiers::Alt) => Some("\x1bS".to_string()),
("t", AlacModifiers::Alt) => Some("\x1bt".to_string()),
("T", AlacModifiers::Alt) => Some("\x1bT".to_string()),
("u", AlacModifiers::Alt) => Some("\x1bu".to_string()),
("U", AlacModifiers::Alt) => Some("\x1bU".to_string()),
("v", AlacModifiers::Alt) => Some("\x1bv".to_string()),
("V", AlacModifiers::Alt) => Some("\x1bV".to_string()),
("w", AlacModifiers::Alt) => Some("\x1bw".to_string()),
("W", AlacModifiers::Alt) => Some("\x1bW".to_string()),
("x", AlacModifiers::Alt) => Some("\x1bx".to_string()),
("X", AlacModifiers::Alt) => Some("\x1bX".to_string()),
("y", AlacModifiers::Alt) => Some("\x1by".to_string()),
("Y", AlacModifiers::Alt) => Some("\x1bY".to_string()),
("z", AlacModifiers::Alt) => Some("\x1bz".to_string()),
("Z", AlacModifiers::Alt) => Some("\x1bZ".to_string()),
// Emacs Numeric arguments / prefix arguments
("0", AlacModifiers::Alt) => Some("\x1b0".to_string()),
("1", AlacModifiers::Alt) => Some("\x1b1".to_string()),
("2", AlacModifiers::Alt) => Some("\x1b2".to_string()),
("3", AlacModifiers::Alt) => Some("\x1b3".to_string()),
("4", AlacModifiers::Alt) => Some("\x1b4".to_string()),
("5", AlacModifiers::Alt) => Some("\x1b5".to_string()),
("6", AlacModifiers::Alt) => Some("\x1b6".to_string()),
("7", AlacModifiers::Alt) => Some("\x1b7".to_string()),
("8", AlacModifiers::Alt) => Some("\x1b8".to_string()),
("9", AlacModifiers::Alt) => Some("\x1b9".to_string()),
// Various Emacs Meta key combinations
("!", AlacModifiers::Alt) => Some("\x1b!".to_string()),
// ("\"", AlacModifiers::Alt) => Some("\x1b\"".to_string()),
// ("#", AlacModifiers::Alt) => Some("\x1b#".to_string()),
("$", AlacModifiers::Alt) => Some("\x1b$".to_string()),
("%", AlacModifiers::Alt) => Some("\x1b%".to_string()),
("&", AlacModifiers::Alt) => Some("\x1b&".to_string()),
("'", AlacModifiers::Alt) => Some("\x1b'".to_string()),
("(", AlacModifiers::Alt) => Some("\x1b(".to_string()),
(")", AlacModifiers::Alt) => Some("\x1b)".to_string()),
// ("*", AlacModifiers::Alt) => Some("\x1b*".to_string()),
// ("+", AlacModifiers::Alt) => Some("\x1b+".to_string()),
(",", AlacModifiers::Alt) => Some("\x1b,".to_string()),
("-", AlacModifiers::Alt) => Some("\x1b-".to_string()),
(".", AlacModifiers::Alt) => Some("\x1b.".to_string()),
("/", AlacModifiers::Alt) => Some("\x1b/".to_string()),
(":", AlacModifiers::Alt) => Some("\x1b:".to_string()),
(";", AlacModifiers::Alt) => Some("\x1b;".to_string()),
("<", AlacModifiers::Alt) => Some("\x1b<".to_string()),
("=", AlacModifiers::Alt) => Some("\x1b=".to_string()),
(">", AlacModifiers::Alt) => Some("\x1b>".to_string()),
("?", AlacModifiers::Alt) => Some("\x1b?".to_string()),
("@", AlacModifiers::Alt) => Some("\x1b@".to_string()),
// ("[", AlacModifiers::Alt) => Some("\x1b[".to_string()),
("\\", AlacModifiers::Alt) => Some("\x1b\\".to_string()),
// ("]", AlacModifiers::Alt) => Some("\x1b]".to_string()),
("^", AlacModifiers::Alt) => Some("\x1b^".to_string()),
// ("_", AlacModifiers::Alt) => Some("\x1b_".to_string()),
("`", AlacModifiers::Alt) => Some("\x1b`".to_string()),
("{", AlacModifiers::Alt) => Some("\x1b{".to_string()),
("|", AlacModifiers::Alt) => Some("\x1b|".to_string()),
("}", AlacModifiers::Alt) => Some("\x1b}".to_string()),
("~", AlacModifiers::Alt) => Some("\x1b~".to_string()),
_ => None,
};
if manual_esc_str.is_some() {
Expand Down

0 comments on commit 66ada3e

Please sign in to comment.