fix: restore kitty keyboard stack on exit - #1750
Open
deepakganesh78 wants to merge 3 commits into
Open
Conversation
Use the Kitty keyboard protocol stack when enabling keyboard enhancements so Bubble Tea can pop its entry on screen switches and shutdown instead of overwriting terminal state. Update renderer goldens and add a regression test for push/pop behavior. Fixes charmbracelet#1749 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Member
|
Super good catch. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1750 +/- ##
==========================================
+ Coverage 56.34% 56.98% +0.63%
==========================================
Files 25 25
Lines 1315 1325 +10
==========================================
+ Hits 741 755 +14
+ Misses 483 481 -2
+ Partials 91 89 -2 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
andrinoff
requested changes
Aug 5, 2026
andrinoff
left a comment
Member
There was a problem hiding this comment.
Hey there @deepakganesh78!
Thank you for your contribution! You've beat me to it 😆
Please, note the review comments below, and try to fix it.
p.s. great work!
Signed-off-by: drew <me@andrinoff.com>
andrinoff
force-pushed
the
fix/issue1749-kitty-keyboard-stack
branch
from
August 12, 2026 13:21
572f646 to
f79bbd5
Compare
Signed-off-by: drew <me@andrinoff.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1749
Reproduction
Issue #1749 reports that Bubble Tea v2 enables Kitty keyboard enhancements but exits with
CSI = 0 ; 1 u, leaving terminals such as WezTerm in the enhanced keyboard state. The addedTestCursedRenderer_restoresKittyKeyboardStackreproduces this programmatically by flushing and closing a renderer and asserting that Bubble Tea pushes a Kitty keyboard stack entry and pops it on close instead of resetting it in place.Root cause
The renderer used
ansi.KittyKeyboard(flags, 1)to set the active keyboard flags andansi.KittyKeyboard(0, 1)to clear them. That overwrites the terminal's current keyboard protocol flags instead of using the Kitty keyboard stack, so Bubble Tea cannot restore the prior terminal state on exit or when switching between main and alternate screen registries.Fix
Use
ansi.PushKittyKeyboard(flags)when Bubble Tea takes ownership of a screen's keyboard enhancements, keep in-place updates for enhancement changes while the same screen is active, and useansi.PopKittyKeyboard(0)when switching screens or closing. The first render directly into the alternate screen avoids popping the main-screen stack when Bubble Tea never pushed it. Renderer golden files were updated for the new escape sequences.Compatibility notes
This preserves Bubble Tea's existing default keyboard enhancement flags while making cleanup stack-balanced for terminals that implement the Kitty keyboard protocol. Non-supporting terminals should continue to ignore these sequences.
modifyOtherKeyscleanup is unchanged.Validation
go test . -run TestCursedRenderer_restoresKittyKeyboardStack -count=1passes with the fix.cursed_renderer.gois reverted to the previous behavior.gofmt -l .produced no output.go build ./...passed.go vet ./...passed.go test ./...passed.