Repository navigation
Expose the shell's prompt/command state from OSC 133 - #192
Conversation
JohnCampionJr
left a comment
There was a problem hiding this comment.
Pre-merge review (Codex), for the PR author
No findings. Checked A/B/C/D mapping, duplicate suppression, exit-code propagation and the existing LastCommandExitCode API, unknown/out-of-order marks, nested shells, RIS versus DECSTR, alternate-screen behavior, raw-mark event ordering and disposal. The changes combine with the word-separator/OSC-terminator and checksum-option PRs without code conflicts. Built against the combined source changes: 107 filtered core tests passed, including shell integration, options, OSC terminators and checksums. The dependent control's lifecycle finding is reported on its PR, not attributed to this emulator API.
aa2d622 to
175864b
Compare
|
Follow-up from the dependent control PR's review (tomlm/Iciclecreek.Avalonia.Terminal#214 (comment)): commit 1840f6d adds one public member here, |
JohnCampionJr
left a comment
There was a problem hiding this comment.
Pre-merge review follow-up (Codex), for the PR author
Rechecked only the changes after my original review, at current head 175864b. The new public ResetShellState() method is sound: it performs the existing deduplicated transition to Unknown with no exit code, while preserving cells, scrollback, anchored marks, and other shell metadata. RIS still uses that transition. A focused preservation/event test and the shell-integration tests passed (69 total). No findings in this delta.
175864b to
2ff859c
Compare
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