Skip to content

Commit

Permalink
Request xterm 'modifyOtherKeys' mode to opt-in CSI u key reporting
Browse files Browse the repository at this point in the history
Various terminal emulators now support this `CSI > 4 ; 1 m` sequence
to enable CSI u style reporting, opt into it on startup.

Closes #4103
  • Loading branch information
mawww committed May 2, 2021
1 parent db9ef82 commit 47c0d20
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/ncurses_ui.cc
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,8 @@ void NCursesUI::set_terminal_mode() const
fputs("\033=", stdout);
// force enable report focus events
fputs("\033[?1004h", stdout);
// request CSI u style key reporting
fputs("\033[>4;1m", stdout);
fflush(stdout);
}

Expand All @@ -420,6 +422,7 @@ void NCursesUI::restore_terminal_mode() const
tcsetattr(STDIN_FILENO, TCSAFLUSH, &m_original_termios);
fputs("\033>", stdout);
fputs("\033[?1004l", stdout);
fputs("\033[>4;0m", stdout);
fflush(stdout);
}

Expand Down

17 comments on commit 47c0d20

@SolitudeSF
Copy link
Contributor

@SolitudeSF SolitudeSF commented on 47c0d20 Jun 11, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

after this commit kakoune leaves (kitty) terminal in bad state breaking other ncurses applications.

@vbauerster
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After quitting kakoune, can you pls run cat and press <c-c>? If kakoune didn't emit exit sequence you would see ^[[99;5u. In my case everything is ok, kitty v0.20.3.

@SolitudeSF
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it terminates cat. do ranger/htop/whatever (cursor keys) work for you?

@SolitudeSF
Copy link
Contributor

@SolitudeSF SolitudeSF commented on 47c0d20 Jun 11, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually, cat exits, but if i press ctrlc inside ranger it does recieve ^[[99;5u

@vbauerster
Copy link
Contributor

@vbauerster vbauerster commented on 47c0d20 Jun 11, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you're right I cannot use F keys in htop after quitting kakoune. Manually issuing printf '\033[>4;1m' and then printf '\033[>4;0m' doesn't break htop, which means problem most likely is not in kitty.

@vbauerster
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It could be bug in kitty, not sure. Same workflow in iTerm2 doesn't brake htop.

@greenfork
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm having same issue with kitty. Checked with alacritty - works fine there. But I don't use alacritty.

@eraserhd
Copy link
Contributor

@eraserhd eraserhd commented on 47c0d20 Jun 17, 2021 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Screwtapello
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kitty users: please try the following:

  • Run these commands:

    tput smcup; printf '\e[>4;1m'; cat
    
    • set mode cursor positioning (the "alternate screen" mode ncurses apps enter)
    • enable extended key reporting
    • cat will just echo the encoding of the keys you press
  • Press <f1>, then <c-9>, then <c-c> to stop cat

    • You should see ^[OP representing the F1 keypress
    • You should see ^[[57;5u representing Ctrl-9
    • You should see ^C representing Ctrl-C
  • Run these commands:

     tput rmcup; cat
    
    • reset mode cursor positioning mode
    • cat will just echo the encoding of the keys you press
  • Press <f1>, then <c-9>, then <c-c> to stop cat

    • You should see ^[OP representing the F1 keypress
    • You should see ^[[57;5u representing Ctrl-9
    • You should see ^C representing Ctrl-C
  • Run these commands:

    printf '\e[>4;0m'; cat
    
    • disable extended key reporting
    • cat will just echo the encoding of the keys you press
  • Press <f1>, then <c-9>, then <c-c> to stop cat

    • You should see ^[OP representing the F1 keypress
    • You should see 9 representing Ctrl-9 (xterm) or nothing (tmux inside xterm)
    • You should see ^C representing Ctrl-C

All the "You should see" lines describe what I see inside the extended-key-reporting apps I have available to me, namely xterm and tmux 3.2a. If Kitty does something different, then... some people somewhere need to talk.

@greenfork
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tput smcup; printf '\e[>4;1m'; cat

^[[P^[[57;5u^[[99;5u and no way to stop cat

tput rmcup; cat

^[OP9^C

printf '\e[>4;0m'; cat

^[OP9^C

@Screwtapello
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And if you change it to:

tput smcup; printf '\e[>4;1m'; printf '\e[>4;0m'; tput rmcup; cat

...then everything works?

If so, it seems like when Kakoune switches to the alternate screen and enables extended key reporting, Kitty enables it only for the alternate screen, and you can't disable it unless you're still on the alternate screen. That's quite different from the way most terminal state works, so I assume it's deliberate for some reason I don't understand. It might be worth filing an issue against Kitty, if only to find out the reason and to give Kitty's author feedback about that particular design decision.

@greenfork
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tput smcup; printf '\e[>4;1m'; printf '\e[>4;0m'; tput rmcup; cat

^[OP9^C - does that mean it works?

@Screwtapello
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, that's what I'd expect

@greenfork
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Screwtapello thank you for your help! I have created a bug report, hopefully we can get it fixed sooner than later kovidgoyal/kitty#3742

@greenfork
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So there's a quick response from the author and he says that the bug is in kakoune. I think someone more knowledgeable should take it further.

@SolitudeSF
Copy link
Contributor

@SolitudeSF SolitudeSF commented on 47c0d20 Jun 18, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue is kakoune disables extended key reporting after switching to main screen.

@greenfork
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Created an issue for kakoune repo #4238

Please sign in to comment.