Skip to content

Conversation

@jquast
Copy link
Owner

@jquast jquast commented Jan 26, 2026

The previous change #191 treated the OSC hyperlink edges as unbreakable, but it still incorrectly broke an OSC hyperlink sequence in half if the hyperlink text also contained spaces.

The most naive approach simply says "nothing ever breaks in a hyperlink", but that means any "long" hyperlink is entirely unbreakable and cannot be wrapped by a word margin, bleeding off the screen or other ill-effect.

To break OSC is complicated. It is necessary to identify and preserve any existing 'id' parameter, or define and generate new unique ones, and to allow wrapping them by closing and re-emitting a new hyperlink sequence of the remaining text, of matching id, at the next line.

You wouldn't think until you get into it, that OSC hyperlink is so much
more work for a word-wrapping algorithm that it first appears. The
previous change just treated the boundaries as unbreakable but it still
(incorrectly) broke an OSC hyperlink if the text contained spaces and a
margin is reached.

The most naive approach simply says "nothing ever breaks in a
hyperlink", but that means any "long" hyperlink is entirely unbreakable
and cannot be wrapped by a word margin.

But to break it is also very complicated, We must identify and preserve
any exting 'id' parameter, or define and generate new unique ones, to
allow wrapping them, by closing and re-emitting (and generating!) a new
hyperlink of matching id at the next line.

We also have to be careful of the word-wrapping rules within, to do the
best to match sensible break_on_long_words, break_on_hyphen, etc.
You would think just generating our own id's, starting with id=1 is
fine, but I guess there is a rare case that the stream already contains
mixed with-and-without ids, and starting with id=1 would be the most
obvious default.

To prevent conflict, we use padded hexadecimal of random generated
values, the famous "git short" length, something like 4 billion-in-1
@jquast jquast changed the title **Bugfix** OSC Hyperlinks can be broken by wrap() Bugfix OSC Hyperlinks when broken mid-text by wrap() Jan 26, 2026
@jquast jquast changed the title Bugfix OSC Hyperlinks when broken mid-text by wrap() Bugfix OSC Hyperlinks when broken mid-text by wrap() Jan 26, 2026
@codspeed-hq
Copy link

codspeed-hq bot commented Jan 26, 2026

Merging this PR will not alter performance

✅ 47 untouched benchmarks
🆕 3 new benchmarks

Performance Changes

Benchmark BASE HEAD Efficiency
🆕 test_wrap_hyperlink_mixed N/A 5.7 ms N/A
🆕 test_wrap_hyperlink_with_id N/A 4.9 ms N/A
🆕 test_wrap_hyperlink_no_id N/A 5.1 ms N/A

Comparing jq/osc-hyperlinks-more-fixes (60d2e05) with master (b297eaf)

Open in CodSpeed

@jquast jquast marked this pull request as ready for review January 26, 2026 19:26
@codecov
Copy link

codecov bot commented Jan 26, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (b297eaf) to head (60d2e05).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff            @@
##            master      #193   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           13        13           
  Lines          668       716   +48     
  Branches       164       175   +11     
=========================================
+ Hits           668       716   +48     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@jquast jquast merged commit 7de2e9b into master Jan 26, 2026
79 of 80 checks passed
@jquast jquast deleted the jq/osc-hyperlinks-more-fixes branch January 26, 2026 22:51
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.

1 participant