Skip to content

Fix Truncater counting OSC hyperlink payloads as printable width - #626

Open
trippyogi wants to merge 3 commits into
Shopify:mainfrom
trippyogi:fix/614-truncater-osc-hyperlinks
Open

Fix Truncater counting OSC hyperlink payloads as printable width#626
trippyogi wants to merge 3 commits into
Shopify:mainfrom
trippyogi:fix/614-truncater-osc-hyperlinks

Conversation

@trippyogi

Copy link
Copy Markdown

Summary

Fixes #614

CLI::UI::Truncater only skipped CSI sequences (ESC [), so OSC hyperlink payloads (ESC ]…) were counted toward printable width and spinner titles truncated early even when ANSI.printing_width was correct.

This change teaches Truncater to consume OSC sequences (BEL and ST / ESC \), close an open OSC 8 hyperlink before emitting the truncation marker when a cut removes the original close, and keep OSC 8 open-state across unrelated OSC sequences (e.g. OSC 9) so a later truncate still closes the link.

Overlap with #624

#624 also covers this class of terminal-width/OSC issues as part of a much broader layout/parser change set, currently aimed at the pending 3.0 work rather than a minimal mainline fix. This PR is intentionally scoped to #614 on current main so maintainers can take the narrow fix independently if desired.

Test plan

  • Exact Truncater counts OSC sequence contents (hyperlinks) as printable width #614 reproduction: formatted hyperlink fits within width and is unchanged
  • Truncation inside an OSC 8 hyperlink emits OSC 8 close before TRUNCATED
  • BEL-terminated OSC sequences are ignored for width
  • OSC 8 remains open across an unrelated OSC (e.g. OSC 9), then closes on truncate
  • bundle exec rake (full suite + RuboCop) — blocked locally on Windows (sorbet-static has no x64-mingw-ucrt platform); please rely on CI
bundle exec rake
# or focused:
bundle exec ruby -Ilib:test test/cli/ui/truncater_test.rb

Truncater only skipped CSI after ESC, so OSC hyperlink payloads counted as printable width and spinner titles truncated early. Mirror ANSI.strip_codes OSC handling (BEL / ST terminators).
When truncation removes a hyperlink's closing sequence, emit OSC 8 end before the ellipsis so later output is not left clickable. Require a real ST backslash after ESC, and keep BEL/ST OSC handling with focused regression coverage.
Non-OSC8 terminators were clearing hyperlink state via osc8_open? returning false. Return nil for non-OSC8 so Truncater still closes dangling links when truncating after sequences like OSC 9.
@trippyogi
trippyogi marked this pull request as ready for review August 13, 2026 19:45
@trippyogi
trippyogi requested a review from a team as a code owner August 13, 2026 19:45
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.

Truncater counts OSC sequence contents (hyperlinks) as printable width

1 participant