aboutsummaryrefslogtreecommitdiff
path: root/src/input
diff options
context:
space:
mode:
authorOgulcan Celik <ogulcancelik@gmail.com>2026-05-19 14:24:30 +0300
committerOgulcan Celik <ogulcancelik@gmail.com>2026-05-19 14:24:30 +0300
commitd616bcd6b86742762fec5f0696a5c13701fe717c (patch)
tree44e20df741c3c587168a351e422a67ede524ca2d /src/input
parent6cbdba434fd15fc3818302a5843593da47db2eb4 (diff)
fix: preserve modified enter input
refs #168
Diffstat (limited to 'src/input')
-rw-r--r--src/input/mod.rs4
-rw-r--r--src/input/model.rs60
2 files changed, 62 insertions, 2 deletions
diff --git a/src/input/mod.rs b/src/input/mod.rs
index b4886256..ab7192c7 100644
--- a/src/input/mod.rs
+++ b/src/input/mod.rs
@@ -7,7 +7,7 @@ pub use encode::{
encode_cursor_key, encode_mouse_button, encode_mouse_scroll, encode_terminal_key,
};
pub use model::{
- ime_compatible_keyboard_enhancement_flags, KeyboardProtocol, MouseProtocolEncoding,
- MouseProtocolMode, TerminalKey,
+ host_modify_other_keys_mode, ime_compatible_keyboard_enhancement_flags, KeyboardProtocol,
+ MouseProtocolEncoding, MouseProtocolMode, TerminalKey,
};
pub use parse::parse_terminal_key_sequence;
diff --git a/src/input/model.rs b/src/input/model.rs
index 95732bbc..5dddebda 100644
--- a/src/input/model.rs
+++ b/src/input/model.rs
@@ -47,6 +47,37 @@ pub fn ime_compatible_keyboard_enhancement_flags() -> KeyboardEnhancementFlags {
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
+pub enum ModifyOtherKeysMode {
+ Mode1,
+ Mode2,
+}
+
+impl ModifyOtherKeysMode {
+ pub fn set_sequence(self) -> &'static [u8] {
+ match self {
+ Self::Mode1 => b"\x1b[>4;1m",
+ Self::Mode2 => b"\x1b[>4;2m",
+ }
+ }
+}
+
+pub fn host_modify_other_keys_mode(
+ in_tmux: bool,
+ term_program: Option<&str>,
+ wezterm_pane: bool,
+) -> Option<ModifyOtherKeysMode> {
+ if in_tmux {
+ return Some(ModifyOtherKeysMode::Mode2);
+ }
+
+ if wezterm_pane || term_program.is_some_and(|program| program.eq_ignore_ascii_case("wezterm")) {
+ return Some(ModifyOtherKeysMode::Mode1);
+ }
+
+ None
+}
+
+#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum KeyboardProtocol {
Legacy,
Kitty { flags: u16 },
@@ -113,4 +144,33 @@ mod tests {
assert!(flags.contains(KeyboardEnhancementFlags::REPORT_ALTERNATE_KEYS));
assert!(!flags.contains(KeyboardEnhancementFlags::REPORT_ALL_KEYS_AS_ESCAPE_CODES));
}
+
+ #[test]
+ fn modify_other_keys_mode_is_enabled_for_tmux() {
+ assert_eq!(
+ host_modify_other_keys_mode(true, Some("WezTerm"), true),
+ Some(ModifyOtherKeysMode::Mode2)
+ );
+ }
+
+ #[test]
+ fn modify_other_keys_mode_is_enabled_for_wezterm_hosts() {
+ assert_eq!(
+ host_modify_other_keys_mode(false, Some("WezTerm"), false),
+ Some(ModifyOtherKeysMode::Mode1)
+ );
+ assert_eq!(
+ host_modify_other_keys_mode(false, None, true),
+ Some(ModifyOtherKeysMode::Mode1)
+ );
+ }
+
+ #[test]
+ fn modify_other_keys_mode_is_not_enabled_for_unknown_hosts() {
+ assert_eq!(
+ host_modify_other_keys_mode(false, Some("ghostty"), false),
+ None
+ );
+ assert_eq!(host_modify_other_keys_mode(false, None, false), None);
+ }
}