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 Kitty Color Protocol (OSC 21) #2113

Merged
merged 9 commits into from
Aug 21, 2024
Merged

Conversation

jcollie
Copy link
Member

@jcollie jcollie commented Aug 17, 2024

Kitty 0.36.0 added support for a new OSC escape sequence for quering, setting, and resetting the terminal colors. Details can be found here.

This fully parses the OSC 21 escape sequences, but only supports actually querying and changing the foreground color, the background color, and the cursor color because that's what Ghostty currently supports. Adding support for the other settings that Kitty supports changing ranges from easy (cursor text) to difficult (visual bell, second transparent background color).

Kitty 0.36.0 added support for a new OSC escape sequence for
quering, setting, and resetting the terminal colors. Details
can be found [here](https://sw.kovidgoyal.net/kitty/color-stack/#setting-and-querying-colors).

This fully parses the OSC 21 escape sequences, but only supports
actually querying and changing the foreground color, the background
color, and the cursor color because that's what Ghostty currently
supports. Adding support for the other settings that Kitty supports
changing ranges from easy (cursor text) to difficult (visual bell,
second transparent background color).
@jcollie jcollie changed the title [WIP] Implement Kitty Color Protocol (OSC 21) Implement Kitty Color Protocol (OSC 21) Aug 17, 2024
@jcollie
Copy link
Member Author

jcollie commented Aug 17, 2024

Unmarked this as a WIP. log.err will result in failed tests...

Copy link
Contributor

@mitchellh mitchellh left a comment

Choose a reason for hiding this comment

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

Very excellent work! Truly! I've noted some changes I'd like to see. Thank you!

- Cap the total number of requests at twice the maximum number of
  keys (currently 263, so 526 requests). Basically you can set and then
  query every key in one message. This is an absurdly high number
  but should prevent serious DOS attacks.
- Clarify meaning of new hex color codes.
- Better handle sending messages to the renderer in a way that should
  prevent deadlocks.
- Handle 0-255 palette color requests by creatively using non-exhautive
  enums.
- Fix an error in the query reply.
Copy link
Contributor

@mitchellh mitchellh left a comment

Choose a reason for hiding this comment

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

Thanks! I want to play around with one thing but the rest looks good.

@mitchellh
Copy link
Contributor

I'm still doing some small tweaks then I plan to merge this. I'd still love to see an approach that doesn't use non-exhaustive enums but I don't think I'll pursue it in this PR. My biggest issue with non-exhaustive enums is that it gets rid of a bunch of nice compiler verification for exhaustion when switching.

I try to only use non-exhaustive enums for C interop or scenarios where we want to be liberal in what we accept. This feature is neither of those.

Like I said, I'll still merge it as is but I'm still making some tweaks.

Copy link
Contributor

@mitchellh mitchellh left a comment

Choose a reason for hiding this comment

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

Couple more changes requested. I can get to them soon or you can, either way. They're small.

@jcollie
Copy link
Member Author

jcollie commented Aug 21, 2024

I'm still doing some small tweaks then I plan to merge this. I'd still love to see an approach that doesn't use non-exhaustive enums but I don't think I'll pursue it in this PR. My biggest issue with non-exhaustive enums is that it gets rid of a bunch of nice compiler verification for exhaustion when switching.

After doing the desktop notifications I think you're right about using a union to separate the two cases rather than the non-exhaustive enum. I can either update this PR now or do a follow-up PR after this merges.

@mitchellh
Copy link
Contributor

After doing the desktop notifications I think you're right about using a union to separate the two cases rather than the non-exhaustive enum. I can either update this PR now or do a follow-up PR after this merges.

I'd appreciate a follow-up PR. I think this one is getting really close to merge-able and I don't want to delay it even more 😄 But a follow up to clean that up would be very nice!

@mitchellh mitchellh merged commit 8df5ec1 into ghostty-org:main Aug 21, 2024
16 of 19 checks passed
@mitchellh mitchellh deleted the osc-21 branch August 21, 2024 13:23
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.

2 participants