Add SendKey key assignment

refs: https://github.com/wez/wezterm/pull/1091
This commit is contained in:
Wez Furlong committed 2021-09-03 12:07:17 -07:00
1 parent 8da1f676a8
commit bc4ed3735d
7 files changed
+50 -1

No files matched your search

+2
View File
@@ -1,3 +1,4 @@
use crate::keys::KeyNoAction;
use crate::ConfigHandle;
use crate::LeaderKey;
use luahelper::impl_lua_conversion;
@@ -166,6 +167,7 @@ pub enum KeyAssignment {
ActivateTab(isize),
ActivateLastTab,
SendString(String),
SendKey(KeyNoAction),
Nop,
DisableDefaultAssignment,
Hide,
+9
View File
@@ -4,6 +4,15 @@ use serde::{Deserialize, Deserializer, Serialize};
use std::collections::HashMap;
use wezterm_input_types::{KeyCode, Modifiers};
#[derive(Debug, Deserialize, Serialize, Clone, PartialEq, Eq)]
pub struct KeyNoAction {
#[serde(deserialize_with = "de_keycode")]
pub key: KeyCode,
#[serde(deserialize_with = "de_modifiers", default)]
pub mods: Modifiers,
}
impl_lua_conversion!(KeyNoAction);
#[derive(Debug, Deserialize, Serialize, Clone)]
pub struct Key {
#[serde(deserialize_with = "de_keycode")]
+1
View File
@@ -26,6 +26,7 @@ As features stabilize some brief notes about them will accumulate here.
* Fixed: X11: jittery resize with some window managers [#1051](https://github.com/wez/wezterm/issues/1051)
* Fixed: X11: [window:get_appearance](config/lua/window/get_appearance.md) now actually returns Dark when the theme is dark. [#1098](https://github.com/wez/wezterm/issues/1098)
* Fixed: ALT + Arrow, PageUp/PageDown, Ins, Del, Home, End incorrectly sent ESC prefixed key sequences. [#892](https://github.com/wez/wezterm/issues/892)
* New: Added [SendKey](config/lua/keyassignment/SendKey.md) key assignment action that makes it more convenient to rebind the key input that is sent to a pane.
### 20210814-124438-54e29167
+29
View File
@@ -0,0 +1,29 @@
# SendKey
*Since: nightly builds only*
Send the specified key press to the current pane. This is useful to rebind
the effect of a key combination.
Note that this rebinding effect only applies to the input that is about to be
sent to the pane; it doesn't get re-evaluated against the key assignments
you've configured in wezterm again.
For example, macOS users often prefer to rebind `Option+LeftArrow` and
`Option+RightArrow` to match the behavior of Terminal.app, where those key
sequences are remapped to `ALT-b` and `ALT-f` which generally causes the
the cursor to move backwards or forwards by one word in most common unix
shells and applications.
The following configuration achieves that same effect:
```lua
local wezterm = require 'wezterm';
return {
keys = {
-- Rebind OPT-Left, OPT-Right as ALT-b, ALT-f respectively to match Terminal.app behavior
{key="LeftArrow", mods="OPT", action={SendKey={key="b", mods="ALT"}}},
{key="RightArrow", mods="OPT", action={SendKey={key="f", mods="ALT"}}},
}
}
```
@@ -32,3 +32,4 @@ return {
}
```
See also [SendKey](SendKey.md) which makes the example above much more convenient.
+1 -1
View File
@@ -238,7 +238,7 @@ impl super::TermWindow {
}
}
fn win_key_code_to_termwiz_key_code(&self, key: &::window::KeyCode) -> Key {
pub fn win_key_code_to_termwiz_key_code(&self, key: &::window::KeyCode) -> Key {
use ::termwiz::input::KeyCode as KC;
use ::window::KeyCode as WK;
+7
View File
@@ -1740,6 +1740,13 @@ impl TermWindow {
self.activate_tab(*n)?;
}
SendString(s) => pane.writer().write_all(s.as_bytes())?,
SendKey(key) => {
use keyevent::{window_mods_to_termwiz_mods, Key};
let mods = window_mods_to_termwiz_mods(key.mods);
if let Key::Code(key) = self.win_key_code_to_termwiz_key_code(&key.key) {
pane.key_down(key, mods)?;
}
}
Hide => {
if let Some(w) = window.as_ref() {
w.hide();