wezterm icon indicating copy to clipboard operation
wezterm copied to clipboard

\033[=0;1u not working as expected

Open unxed opened this issue 3 years ago • 1 comments

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

Linux X11

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

Muffin

WezTerm version

wezterm 20230415-235902-6ec11393

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

Try

printf '\033[=31u\033[=0;1u'

This should enable kitty enhanced keyboard mode and disable back. After it, try to press arrow keys (up arrow, for example) in bash. You will get "A" char instead of scrolling to previously typed command.

To Reproduce

printf '\033[=31u\033[=0;1u'
  1. Press UpArrow

Configuration

no config

Expected Behavior

kitty mode should be disabled, up arrow should show previously typed command

Logs

No response

Anything else?

No response

unxed avatar Apr 22 '23 22:04 unxed

Workaround: use \033[>31u and \033[<u instead.

unxed avatar Aug 21 '24 23:08 unxed

@wez this seems to be affecting vim directly, though I don't know if you want a separate bug report. Vim uses ^[[=0;1u to disable the kitty protocol when it exits (see here: link). The fact that =0;1u is not working means that starting and then exiting vim break a lot of the keys in the terminal. This is on wezterm 20240203-110809-5046fc22 and vim 9.1.0720.

Right now I'm working around it in vim itself by editing t_TE to the value @unxed provided, but it's not very convenient.

jmdevin avatar Sep 17 '24 04:09 jmdevin

Just adding this issue has appeared in Fish shell 4 beta, when using Wezterm and Fish shell together, the git pager doesn't work correctly if the kitty keyboard protocol is enabled.

The navigation for using the arrow keys or page-up/page-down to move the screen stop working.

Things return to normal if kitty keyboard protocol is disabled in Wezterm config file.

ardrigh avatar Jan 16 '25 00:01 ardrigh

This is because WezTerm incorrectly implements kitty's Legacy key event encoding. However, this section is not meant to be implemented as a protocol that can be activated. It merely describes the default plain behavior of kitty, which is simply general behavior that most terminals implement very similarly and which must conform to terminfo. As a consequence, there is no mechanism to turn this mode on or off in the kitty specification.

Therefore, WezTerm should not implement the legacy behavior of kitty at all, because its default behavior is already fully sufficient for that purpose. WezTerm (and other terminals) should implement only Progressive enhancements, which are fully switchable. Setting the progressive enhancement flags to 0 should disable the kitty protocol completely. Currently, setting the flags to 0 only switches WezTerm into this "kitty legacy mode", which can't be disabled in any other way than by sending the pop (CSI < u) sequence repeatedly until there is no pushed state left in the kitty enhancement flags stack.

As already noted, this bug is reproducible, for example, when using vim: enable config.enable_kitty_keyboard, launch vim, and then exit vim. After that, the arrow keys will not work in bash, producing incompatible kitty sequences. (To make it even worse, unlike kitty itself, WezTerm produces incompatible legacy sequences because it incorrectly sends Num Lock and Caps Lock modifier codes, which are not allowed in legacy mode, and it also sends modifier code even when no modifier is set, which also conflicts with kitty's legacy mode.)

I'll submit a PR that treats progressive enhancement flags set to 0 as meaning the kitty is completely disabled, which is the correct behavior.

horkykuba avatar Oct 18 '25 13:10 horkykuba

Relates to: #6434

horkykuba avatar Oct 18 '25 13:10 horkykuba