Commit 55642c2
committed
fix(cli): adopt DA1 sandwich technique for robust OSC color query detection (#986)
Replace ad-hoc environment checks (CI, Warp, tmux, Docker) with a
comprehensive `is_osc_query_unsupported()` pre-screen modelled after
`terminal-colorsaurus`, and implement the DA1 sandwich technique to
detect unsupported terminals at runtime without waiting for timeouts.
Key changes:
- Centralized quirks detection covering CI, Docker, devcontainers,
Kubernetes, Emacs, GNU Screen, Eterm, tmux, and TERM=dumb
- DA1 sentinel query appended after OSC queries; if its response
arrives first the terminal doesn't support OSC and we bail immediately
- drain_da1() consumes the trailing DA1 response to prevent leaks
- BEL terminator instead of ST to work around urxvt response bug
- SSH-aware timeout (1000ms vs 200ms local)
- Ported regression test from terminal-colorsaurus issue #38
- Extended test coverage for parsing edge cases
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
<!-- CURSOR_SUMMARY -->
---
> [!NOTE]
> **Medium Risk**
> Changes low-level `/dev/tty` I/O and escape-sequence parsing to avoid hangs/leaked output across many terminal environments; mistakes could regress header color detection or terminal interaction timing.
>
> **Overview**
> Makes Vite+ header color probing **more robust across terminal emulators and container/CI environments** by replacing ad-hoc OSC query handling with a centralized `is_osc_query_unsupported()` gate plus the *DA1 sandwich* technique to detect lack of OSC support without waiting for timeouts.
>
> Reworks `query_terminal_colors` to send **BEL-terminated** OSC queries (urxvt workaround), parse responses **sequentially from the tty stream** via `BufReader` (with a poll-based, deadline-aware reader), and drain trailing DA1 output; also adds SSH-aware timeouts.
>
> Expands unix test coverage for hex/RGB parsing, BEL termination, mixed-response buffers, `read_until_either`, and includes a regression test ensuring `query_terminal_colors` doesn’t hang in CI.
>
> <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit a2f3399. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->1 parent 7f2fee5 commit 55642c2
1 file changed
Lines changed: 414 additions & 70 deletions
0 commit comments