wez / wezterm

A GPU-accelerated cross-platform terminal emulator and multiplexer written by @wez and implemented in Rust
https://wezfurlong.org/wezterm/
Other
17.16k stars 774 forks source link

bug: CTRL+SHIFT+h does not get correctly encoded #5201

Open gabyx opened 6 months ago

gabyx commented 6 months ago

What Operating System(s) are you seeing this problem on?

Linux Wayland

Which Wayland compositor or X11 Window manager(s) are you using?

Sway

WezTerm version

889f8a9

Did you try the latest nightly build to see if the issue is better (or worse!) than your current version?

Yes, and I updated the version box above to show the version of the nightly that I tried

Describe the bug

Setting

config.enable_csi_u_key_encoding = true
config.enable_kitty_keyboard = true
config.debug_key_events = true -- Start `wezterm start --always-new-process` to see the keys
config.disable_default_key_bindings = true

and debugging the key combo CTRL+SHIFT+h results in kitty kitten show_key -m kitty as:

 LEFT_CONTROL PRESS
CSI 57442 ; 1 u

ctrl+LEFT_SHIFT PRESS
CSI 57441 ; 5 u

shift+ctrl+h PRESS H
CSI 104 : 72 ; 6 ; 72 u
Shifted key: H

shift+ctrl+h RELEASE
CSI 104 : 72 ; 6 : 3 u
Shifted key: H

shift+ctrl+LEFT_SHIFT RELEASE
CSI 57441 ; 6 : 3 u

ctrl+LEFT_CONTROL RELEASE
CSI 57442 ; 5 : 3 u

with CTRL+v and then CTRL+SHIFT+h results in ^[[104;6u. (this get correctly treated with a tmux bind key bind-key -n "C-S-h" ...)

The same in wezterm:

20:32:30.372  INFO   wezterm_gui::termwindow::keyevent     > key_event RawKeyEvent { key: Physical(LeftControl), modifiers: NONE, leds: (empty), phys_code: Some(LeftControl), raw_code: 37, repeat_count: 1, key_is_down: true, handled: Handled(false) }
20:32:30.372  INFO   wezterm_gui::termwindow::keyevent     > key_event KeyEvent { key: LeftControl, modifiers: NONE, leds: (empty), repeat_count: 1, key_is_down: true, raw: Some(RawKeyEvent { key: Physical(LeftControl), modifiers: NONE, leds: (empty), phys_code: Some(LeftControl), raw_code: 37, repeat_count: 1, key_is_down: true, handled: Handled(false) }) }
20:32:30.372  INFO   wezterm_gui::termwindow::keyevent     > send to pane DOWN key=LeftControl mods=NONE
20:32:30.373  ERROR  window::os::wayland::window           > set_cursor: Cursor not found
20:32:30.399  INFO   wezterm_gui::termwindow::keyevent     > key_event RawKeyEvent { key: Physical(LeftShift), modifiers: CTRL, leds: (empty), phys_code: Some(LeftShift), raw_code: 50, repeat_count: 1, key_is_down: true, handled: Handled(false) }
20:32:30.399  INFO   wezterm_gui::termwindow::keyevent     > key_event KeyEvent { key: LeftShift, modifiers: CTRL, leds: (empty), repeat_count: 1, key_is_down: true, raw: Some(RawKeyEvent { key: Physical(LeftShift), modifiers: CTRL, leds: (empty), phys_code: Some(LeftShift), raw_code: 50, repeat_count: 1, key_is_down: true, handled: Handled(false) }) }
20:32:30.399  INFO   wezterm_gui::termwindow::keyevent     > send to pane DOWN key=LeftShift mods=CTRL
20:32:30.640  INFO   wezterm_gui::termwindow::keyevent     > key_event RawKeyEvent { key: Physical(H), modifiers: SHIFT | CTRL, leds: (empty), phys_code: Some(H), raw_code: 43, repeat_count: 1, key_is_down: true, handled: Handled(false) }
20:32:30.640  INFO   wezterm_gui::termwindow::keyevent     > key_event KeyEvent { key: Char('H'), modifiers: CTRL, leds: (empty), repeat_count: 1, key_is_down: true, raw: Some(RawKeyEvent { key: Physical(H), modifiers: SHIFT | CTRL, leds: (empty), phys_code: Some(H), raw_code: 43, repeat_count: 1, key_is_down: true, handled: Handled(false) }) }
20:32:30.640  INFO   wezterm_gui::termwindow::keyevent     > send to pane DOWN key=Char('H') mods=CTRL
20:32:30.640  INFO   wezterm_term::terminalstate::keyboard > key_down: sending "\u{1b}[72;5u", Char('H') CTRL

and with CTRL+v and then CTRL+SHIFT+h results in ^[[72;5u

To Reproduce

See above.

Configuration

-- Pull in the wezterm API
local wezterm = require("wezterm")
local environment = require("environment")
local astrodark = require("colors/astrodark")

local act = wezterm.action
local mux = wezterm.mux

-- This table will hold the configuration.
local config = {}

-- In newer versions of wezterm, use the config_builder which will
-- help provide clearer error messages
if wezterm.config_builder then
    config = wezterm.config_builder()
end

wezterm.on("gui-startup", function()
    local _, _, window = mux.spawn_window({})
    window:gui_window():maximize()
end)

config.set_environment_variables = {
    TERMINFO_DIRS = os.getenv("HOME") .. "/.terminfo" .. ":" .. os.getenv("TERMINFO_DIRS"),
    WSLENV = "TERMINFO_DIRS",
}
-- Setting it to `wezterm` disable cursor small/bold in the vim plugin.
config.term = "xterm-256color"

-- This is where you actually apply your config choices
config.colors = astrodark.colors()
config.window_frame = astrodark.window_frame()

config.font_size = 12
config.warn_about_missing_glyphs = false
config.font = wezterm.font_with_fallback({
    { family = "JetBrainsMono Nerd Font", weight = "Medium" },
    { family = "Noto Color Emoji", weight = "Medium" },
})

-- config.font_rules = {
--     {
--         intensity = "Normal",
--         italic = true,
--         font = wezterm.font({
--             family = "JetBrainsMono Nerd Font",
--             italic = true,
--             weight = "Medium",
--         }),
--     },
--     {
--         intensity = "Bold",
--         italic = false,
--         font = wezterm.font({
--             family = "JetBrainsMono Nerd Font",
--             weight = "ExtraBold",
--         }),
--     },
--     {
--         intensity = "Bold",
--         italic = true,
--         font = wezterm.font({
--             family = "JetBrainsMono Nerd Font",
--             italic = true,
--             weight = "ExtraBold",
--         }),
--     },
-- }

if environment.os == "linux" then
    config.window_decorations = "NONE"
else
    config.window_decorations = "INTEGRATED_BUTTONS|RESIZE"
end

config.hide_tab_bar_if_only_one_tab = true
config.enable_csi_u_key_encoding = true
config.enable_kitty_keyboard = true
config.debug_key_events = true -- Start `wezterm start --always-new-process` to see the keys
config.disable_default_key_bindings = true

config.leader = { key = "n", mods = "CTRL", timeout_milliseconds = 1000 }
config.keys = {
    -- Copy
    { key = "c", mods = "SHIFT|CTRL", action = act.CopyTo("Clipboard") },
    -- { key = "c", mods = "SUPER", action = act.CopyTo("Clipboard") },

    -- Paste
    { key = "v", mods = "SHIFT|CTRL", action = act.PasteFrom("Clipboard") },
    -- { key = "v", mods = "SUPER", action = act.PasteFrom("Clipboard") },

    -- Leader stuff
    { key = "p", mods = "LEADER", action = act.ActivateCommandPalette },
    { key = "n", mods = "LEADER", action = act.SpawnWindow },

    -- Font Size
    { key = "=", mods = "LEADER", action = act.IncreaseFontSize },
    { key = "-", mods = "LEADER", action = act.DecreaseFontSize },
}

-- and finally, return the configuration to wezterm
return config

Expected Behavior

The correct escaping sequence as in kitty is send to the process.

Logs

No response

Anything else?

No response

goyalyashpal commented 6 months ago