zellij: Shift modifier not working/recognised in conjunction with other modifier keys when inside Zellij session
Basic information
zellij --version:
0.41.1
stty size:
78 150
Issue description
Whenever I am inside a zellij in any terminal (tried 3 different ones), the shift modifier key is not picked up as a modifier key, when used in combination with others.
This is mostly an issue when using terminal editors like vim, since I have a keybinding with shift+alt+s to do :w or write_file.
As the most minimal example, a use case flow would be:
- I can write uppercase letters ie. ABCD with no issue
- I can not write my files with the key combination of shift+alt+s. Only alt+s combination is picked up.
If I am not inside Zellij, I can do above use flow without issues. The bug seem to only exists when I am within a zellij session.
Minimal reproduction
Terminal: Ghostty Editor: Helix 1 Enter a zellij session 2 Open a file with Helix (or vim) 3 Hit shift+alt+s 4 Only alt+s gets picked up.
Extra relevant information
1 No /tmp/zellij-log file was produced when running with $ zellij --debug for some reason.
2 I don’t think it makes sense to show this in a video recording, but I am happy to record one if needed.
Thanks for a great tool!
About this issue
- Original URL
- State: open
- Created 2 years ago
- Reactions: 9
- Comments: 33 (10 by maintainers)
Commits related to this issue
- Install `kitty` by default. This is extremely useful for testing KKP. The following works in any terminal emulator: ``` kitten show-key -m kitty ``` See: https://github.com/zellij-org/zellij/issues... — committed to mjrusso/nixos-config by mjrusso 2 years ago
- Handle KKP implementations that don't support "report alternate keys". Such as Zellij. See: https://github.com/zellij-org/zellij/issues/3789#issuecomment-2569862441 — committed to mjrusso/.emacs.d by mjrusso 2 years ago
In a duplicate thread https://github.com/zellij-org/zellij/issues/3817 a short term fix was provided by OP: https://github.com/zellij-org/zellij/issues/3817#issuecomment-2515313357
TL;DR: Basically setting this option in config.kdl:
support_kitty_keyboard_protocol falseThis seemingly does remove the keybinding issue, although I have to properly investigate. Tested this in Ghostty and Alacritty.
While I don’t believe this issue should be resolved from doing this config, I believe it can act as an intermediate solution until @imsnif or likeminded can implement a fix.
FWIW, using the method listed here to read input events, it seems to me that the issue may lie in the fact that, for a generic key
Swith the aforementioned modifiers, Zellij sendsAlt + Shift + sinstead ofAlt + S, which could be misinterpreted by applications such as Helix.Also of note, with the procedure replicated outside Zellij (tested in both Alacritty and Kitty), the received event is
Alt + Sand the binding works in Helix, whereas it doesn’t inside a Zellij session.It also seems that #3817 is a duplicate of this issue. Anyway, thanks for looking into it and working on Zellij!
Edit: the behaviour is different in Konsole where the key events sent do not change, whether in Zellij or not. Could it be linked to Kitty’s keyboard enhancement protocol, as it seems to not be supported by Konsole?
Hey, so I had a chance to look into this and I’m sorry to say but at least in my view this is an issue with Helix (or crossterm, depending on how you look at it).
Technical explanation
Zellij uses only the first progressive enhancement level of the Kitty Keyboard Protocol “Disambiguate escape codes” (https://sw.kovidgoyal.net/kitty/keyboard-protocol/#disambiguate). In this enhancement level, we report
Alt Shift sas lowercaseswith theAltandShiftmodifiers. This is what the protocol tells us to do, to quote:“The unicode-key-code above is the Unicode codepoint representing the key, as a decimal number. For example, the A key is represented as 97 which is the unicode code for lowercase a. Note that the codepoint used is always the lower-case (or more technically, un-shifted) version of the key. If the user presses, for example, ctrl+shift+a the escape code would be CSI 97;modifiers u. It must not be CSI 65; modifiers u.” (reference: https://sw.kovidgoyal.net/kitty/keyboard-protocol/#key-codes).
Helix, through crossterm, queries the terminal support for the Kitty Keyboard Protocol. Crossterm however, only returns a
bool. Basically, supported/not-supported: https://github.com/crossterm-rs/crossterm/blob/fc8f9779382b7faa7f92bc40d72f8dcbd5849296/src/terminal/sys/unix.rs#L186This means that there is no room left for the particularities of the protocol. Namely - allowing terminals to only support the first progressive enhancement as Zellij does. It’s either on or off.
Helix then assumes that if the protocol is on, it can also accept additional progressive enhancement levels such as
REPORT_ALTERNATE_KEYS, seen here: https://github.com/helix-editor/helix/blob/4c8175ca04dd18a74e8d1a5973042b89a381e3ce/helix-tui/src/backend/crossterm.rs#L184In this progressive enhancement, Helix expects to receive an uppercase
Sin this example as explained in the original protocol: “If alternate key reporting is requested by the program running in the terminal, the terminal can send two additional Unicode codepoints, the shifted key and base layout key, separated by colons.” (reference: https://sw.kovidgoyal.net/kitty/keyboard-protocol/#key-codes). But since Zellij does not support this enhancement (and indeed reports that it does not when queried), we keep sending the unshifted variant of the character with the specifiedAltandShiftmodifiers.There is unfortunately not much I can do on the Zellij side here. The protocol is extremely explicit on the way the terminal (Zellij in this case) should behave, and we are complying with it.
So why does this work in…
The reason this works outside of Zellij in terminals that support the kitty keyboard protocol: likely these terminals support the relevant progressive enhancement that Helix is hard-codedly expecting.
The reason this works outside of Zellij in terminals that do not support the kitty keyboard protocol (or when disabling the protocol in Zellij): this then falls back to the classic STDIN parsing which happens to support this additional modifier.
So - what now?
I would recommend Helix (either through crossterm if possible or on its own) query the host terminal to make sure it supports both progressive enhancements it expects and only expect the behavior that the terminal advertizes it supports.
I would also recommend crossterm make the query command less ambiguous, supporting the particularities of the protocol’s progressive enhancement. Either that or provide an additional query interface that queries the specific progressive enhancement levels.
I’m sorry to give such an answer - I’d rather have solved this on the Zellij-side of course rather than kick the ball down the road. But given that we’re talking about a protocol that is extremely explicit about the way applications should behave, changing the Zellij behavior would be wrong here and likely cause unexpected side-effects.
Hey @blixenkrone - this issue is on my to-fix (or rather, to investigate and then fix if it’s a Zellij issue). My GitHub Sponsors is linked at the top of this repo and here for convenience: https://github.com/sponsors/imsnif - do with this info as you wish.
My personal opinion on bounty systems as a full-time OSS dev: please avoid bounty systems and middle-person OSS sponsoring platforms in general. Give directly to maintainers, everything else is noise at best or actively takes money out of our pockets at worst. Not going to expand on this further, just something to think about.
Thanks for your report and for caring about OSS sustainability.
Hey @the-mikedavis - thanks for taking care of this. The only pity in this scenario is that Helix+Zellij users will not be able to enjoy some multiple modifiers within Helix (with Zellij they should work normally).
I definitely understand where you’re coming from though! If there’s anything else I can do to assist, please feel free to reach out.
(I’m not closing this issue because I don’t generally do - open issues in this repo don’t necessarily indicate a problem and users often use them to communicate solutions and workarounds with each other - as has been happening here on the emacs side).
Dear @frobware - please read the rest of this thread. Specifically https://github.com/zellij-org/zellij/issues/3789#issuecomment-2519953453
Otherwise, I’m unsubscribing from this thread. I’m sorry but I don’t feel I have a lot more to add to this and the notifications are a bit distracting. If the-mikedavis or any other developer of a related app needs assistance, please tag me. Please only tag me in this case. Thanks!
Thanks again, this clears everything out. I will see to open an issue on the Helix repo as well, then. Have a nice day!
@Iorvethe Good thoughts, thanks for the write up.
I think it’s the inverse, but your point still stands. Different key interpretations between applications may be a reason. I’ll try to tinker a bit with the bindings to verify.
It’s not a full solution though, some of vim/vimlike/helix builtin keybindings still rely on the shift modifier to work properly. We still need an implementation that ensures parity between applications keymaps.