Skip to content

Bugfix: OSC Hyperlinks should not be broken by wrap()#191

Merged
jquast merged 4 commits intomasterfrom
jq/wrap-hyperlink-fix
Jan 26, 2026
Merged

Bugfix: OSC Hyperlinks should not be broken by wrap()#191
jquast merged 4 commits intomasterfrom
jq/wrap-hyperlink-fix

Conversation

@jquast
Copy link
Copy Markdown
Owner

@jquast jquast commented Jan 25, 2026

Treat OSC hyperlinks as "word boundaries" for wrap.

OSC hyperlinks are interesting, we can also give them "ids", and, it should be possible to break hyperlinks among multiple lines, by terminating and re-emiting hyperlink at the next line with the same ID. When implemented correctly, both lines would give clickable "hover" effect. I might submit such a PR later.

In practice OSC hyperlinks are rarely used. They are a bit of a security issue for terminals the same as for web browsers, requiring more careful parsing and UX hints to prevent deceptive clickjacking and misleading urls. Most have opted to allow hyperlinks printed plainly as clickable instead, which poses no security risk as its obvious what the url is before clicking.

Came across a failing test while integrating with pytermgui, what an
obvious idea, that OSC hyperlinks should not be broken by textwrap. This
is a failing test we hope to make successful without too much
performance impact.
@codspeed-hq
Copy link
Copy Markdown

codspeed-hq bot commented Jan 25, 2026

Merging this PR will not alter performance

✅ 38 untouched benchmarks


Comparing jq/wrap-hyperlink-fix (7ca473c) with master (c3310f9)

Open in CodSpeed

@codecov
Copy link
Copy Markdown

codecov bot commented Jan 25, 2026

Codecov Report

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

Additional details and impacted files
@@            Coverage Diff            @@
##            master      #191   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           13        13           
  Lines          606       618   +12     
  Branches       146       150    +4     
=========================================
+ Hits           606       618   +12     

☔ 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 marked this pull request as ready for review January 25, 2026 22:32
@jquast jquast merged commit b1cdbdf into master Jan 26, 2026
43 checks passed
@jquast jquast deleted the jq/wrap-hyperlink-fix branch January 26, 2026 02:03
jquast added a commit that referenced this pull request 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.
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