Repository navigation
Expose the shell's prompt/command state from OSC 133 - #192
Merged
Merged
Conversation
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.
Why
A host that wants to confirm before closing a terminal, but only when closing would kill something, needs to ask whether a command is running. That's Ghostty's prompt-aware confirm-close-surface: ask while a command runs, close quietly at an idle prompt. OSC 133 already carries the answer, and
ShellIntegrationStateexposes the raw last mark. But a host still has to map four marks plus null onto "running or not", and it has no change event, so it can't react without polling.API (additive)
XTerm.Common.ShellStateenum:Unknown,Prompt,Input,Running.Terminal.ShellState, read-only.Terminal.ShellStateChanged, withTerminalEvents.ShellStateChangedEventArgs(OldState, NewState, ExitCode). It fires only when the value actually changes.ExitCodeis the code from the133;Dthat ended a command, and null otherwise.Terminal.ResetShellState(): back toUnknown, leaving the screen, the scrollback and the anchored marks alone. It's for a host that connects the terminal to a different process; without it, a new shell that never sends a mark would be described forever by the old shell's last one. RIS uses it too.The transitions are documented on the enum:
A→ Prompt,B→ Input,C→ Running.D→ Prompt. The command is over and the shell has the terminal back. It isn't Unknown, because the shell just said where it is.Each mark sets the state outright, so the latest mark always wins:
D(a crashed shell, a killed command) is repaired by the next prompt'sA.Compatibility
Purely additive.
ShellIntegrationState,LastCommandExitCodeandShellIntegrationMarkReceivedare unchanged.ShellStateis updated before the existing mark event is raised, so a mark handler that reads it sees the new value. The OSC 133 handler is not on the hot path.Tests
ShellIntegrationTestsgains 17 cases:ResetShellStateforgetting the state but not the screen;All 50 tests in the class pass. Mutation runs killed all 10 mutants:
ResetShellState;ResetShellState;The README's events section documents the API.
🤖 Generated with Claude Code