Commit 6754cde
authored
fix(core): drain stdin on exit to prevent escape sequence leakage (#34134)
## Current Behavior
When exiting the TUI (especially via Ctrl+C), escape sequences leak to
the terminal:
```
^[]11;rgb:2121/2121/2121^[\^[[55;1R^[[?62;22;52c
```
This happens because the TUI queries terminal background color via OSC
11 to detect dark/light mode. The terminal responds with an escape
sequence, but if the program exits before fully consuming the response,
it appears in the terminal output.
## Expected Behavior
Clean terminal state after TUI exits, with no escape sequence artifacts.
## Related Issue(s)
N/A - discovered during development
## Solution
Added `drain_stdin()` function that polls and consumes any pending
terminal events before disabling raw mode. This clears any lingering OSC
responses (like the background color query response) before the terminal
is restored.
```rust
fn drain_stdin() {
use std::time::Duration;
while crossterm::event::poll(Duration::from_millis(5)).unwrap_or(false) {
let _ = crossterm::event::read();
}
}
```
The 5ms timeout is long enough to catch pending responses but short
enough not to noticeably delay exit.1 parent 4202f2c commit 6754cde
3 files changed
Lines changed: 37 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
571 | 571 | | |
572 | 572 | | |
573 | 573 | | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
574 | 578 | | |
575 | 579 | | |
576 | 580 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
6 | | - | |
| 6 | + | |
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| |||
53 | 53 | | |
54 | 54 | | |
55 | 55 | | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
56 | 68 | | |
57 | 69 | | |
58 | 70 | | |
| |||
75 | 87 | | |
76 | 88 | | |
77 | 89 | | |
78 | | - | |
79 | | - | |
80 | | - | |
81 | | - | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
82 | 94 | | |
83 | 95 | | |
84 | 96 | | |
85 | 97 | | |
86 | | - | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
87 | 107 | | |
88 | 108 | | |
89 | 109 | | |
| |||
278 | 298 | | |
279 | 299 | | |
280 | 300 | | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
281 | 305 | | |
282 | 306 | | |
283 | 307 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
| 32 | + | |
32 | 33 | | |
33 | | - | |
| 34 | + | |
| 35 | + | |
34 | 36 | | |
35 | 37 | | |
36 | 38 | | |
| |||
0 commit comments