Skip to content

fix(tui): restore kitty keyboard protocol and TUI modes on signal exit (closes #1635) - #1707

Open
alecuba16 wants to merge 1 commit into
1jehuang:masterfrom
alecuba16:fix/terminal-restore-sigint-kitty-pop
Open

alecuba16 wants to merge 1 commit into
1jehuang:masterfrom
alecuba16:fix/terminal-restore-sigint-kitty-pop

Conversation

@alecuba16

Copy link
Copy Markdown
Contributor

Closes #1635. Related #898.

The signal handler (SIGINT/SIGTERM/SIGHUP/SIGQUIT) restored raw mode, the primary screen and the cursor but never popped the kitty keyboard stack nor disabled bracketed paste, focus reporting or mouse capture. A signal exit could therefore leave the terminal in CSI u mode and the shell echoed raw sequences like e1;1:3u.

The handler now disables every TUI mode and calls disable_keyboard_enhancement() before exiting. The pop is a no-op on terminals with no kitty stack, so it is safe unconditionally. This is the signal-exit path; #898 covers the same leak on the normal-exit path inside tmux.

Also one-line ..Default::default() fix in provider_setup to keep a struct literal compiling after new fields.

11 insertions, no behavior change on the normal-exit path. Single commit rebased onto current master.

@greptile-apps

greptile-apps Bot commented Oct 4, 2026 •

Copy link
Copy Markdown

RetriggerConfidence Score: 5/5

[High impact] No outstanding findings block merging. The current code addresses both numbered previous findings.

Summary

This PR restores terminal modes on signal exit and tracks who owns the keyboard settings.

  • Signal exits restore the terminal modes jcode enabled.
  • The TUI tracks which Kitty keyboard entry belongs to jcode.
  • Editor handoffs keep signal cleanup aligned with terminal ownership.

Both numbered previous findings are addressed. No outstanding findings block merging.

Reviews (11) · Last reviewed commit: "fix(tui): restore kitty keyboard protoco..." · Reviewed by Greptile

Comment thread src/cli/terminal.rs Outdated
Comment thread src/cli/commands/provider_setup.rs Outdated
@alecuba16
alecuba16 force-pushed the fix/terminal-restore-sigint-kitty-pop branch from 24f25e3 to af8e737 Compare October 9, 2026 08:12
Comment thread src/cli/terminal.rs Outdated
Comment thread crates/jcode-tui/src/tui/mod.rs
Comment thread crates/jcode-tui/src/tui/mod.rs
Comment thread crates/jcode-tui/src/tui/mod.rs Outdated
@alecuba16
alecuba16 force-pushed the fix/terminal-restore-sigint-kitty-pop branch from bce08bd to 624defc Compare October 9, 2026 12:37
Comment thread src/cli/terminal.rs Outdated
Comment thread crates/jcode-tui/src/tui/app/commands.rs Outdated
Comment thread crates/jcode-tui/src/tui/app/commands.rs Outdated
@alecuba16
alecuba16 force-pushed the fix/terminal-restore-sigint-kitty-pop branch from cf361f5 to 67f65d2 Compare October 9, 2026 17:14
Comment thread crates/jcode-tui/src/tui/app/commands.rs
@alecuba16
alecuba16 force-pushed the fix/terminal-restore-sigint-kitty-pop branch from 67f65d2 to 05d8200 Compare October 9, 2026 18:18
Comment thread crates/jcode-tui/src/tui/app/commands.rs
The SIGINT/SIGTERM/SIGHUP/SIGQUIT handler restored raw mode, the primary screen and the cursor but never popped the kitty keyboard stack nor disabled bracketed paste, focus reporting or mouse capture, so a signal exit left the shell echoing raw sequences like e1;1:3u. The cleanup now disables every TUI mode and pops the kitty stack, writing the disable sequences to stdout where setup_terminal armed them, and skips the pop when this process owns no stack entry. Ownership is tracked process-wide, set on enable, adopted when an exec handoff inherits the previous process's entry, and the push, ownership flip and signal cleanup serialize under one mutex so termination waits out an in-flight push/pop instead of exiting with the entry active.

While an editor owns the tty the cleanup leaves terminal modes alone, and the editor handoff publishes only after suspend finished and reclaims before resume re-arms, both under the kitty state lock, so the cleanup never sees a half-applied handoff. Terminal-mode tests pin the skip, single-pop and no-test-bytes-on-stdout semantics, and the editor test child waits on a sentinel the sampler writes once it observes ownership instead of a fixed sleep.

Closes 1jehuang#1635. Related 1jehuang#898.
@alecuba16
alecuba16 force-pushed the fix/terminal-restore-sigint-kitty-pop branch from 05d8200 to 9217b68 Compare October 9, 2026 19:17
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.

fix(tui): SIGINT/SIGTERM exit leaves kitty keyboard protocol and TUI modes enabled

1 participant