Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Enable/Disable/Detect Kitty Keyboard Protocol #159

Closed
wants to merge 2 commits into from

Conversation

maaslalani
Copy link
Collaborator

This PR allows for enabling and disabling kitty keyboard protocol.

https://sw.kovidgoyal.net/kitty/keyboard-protocol/

This PR adds for returning the progressive enhancements so that the terminal
application can detect which features are supported.

KittyKeyboardProtocolSupport() byte

The byte returned represents the bitset of supported flags.

0b1     (01) — Disambiguate escape codes
0b10    (02) — Report event types
0b100   (04) — Report alternate keys
0b1000  (08) — Report all keys as escape codes
0b10000 (16) — Report associated text

@@ -113,6 +113,79 @@ func (o Output) backgroundColor() Color {
return ANSIColor(0)
}

func (o Output) kittyKeyboardProtocolSupport() byte {
Copy link
Collaborator

Choose a reason for hiding this comment

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

We probably want to combine both this and termStatusReport into one routine that gets executed when the output is being initialized. Right now, both kittyKeyboardProtocolSupport & termStatusReport will set the tty termios and read the envs before reading the response. This results in multiple unnecessary calls to GetTermios/SetTermios and Getenv.

Instead, we could define an initialize function that queries the terminal once. However, I believe this might break things since we query the terminal during the lifetime of WithColorCache https://github.com/muesli/termenv/pull/159/files#diff-35d16970a063a59d666ecdce46f6ac3363f36d17a3e672d8ff69f9ef2056d4cbR114

cc/ @muesli

// 0b100 (04) — Report alternate keys
// 0b1000 (08) — Report all keys as escape codes
// 0b10000 (16) — Report associated text.
func (o Output) KittyKeyboardProtocolSupport() byte {
Copy link
Owner

Choose a reason for hiding this comment

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

Might be worth introducing constants for these return values.


// first, send CSI query to see whether this terminal supports the
// kitty keyboard protocol
fmt.Fprintf(tty, CSI+"?u")
Copy link
Owner

Choose a reason for hiding this comment

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

I assume other terminals simply ignore these queries? We should test this with the common set of terminals we usually test against.

@maaslalani maaslalani closed this Aug 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants