Bugfix: OSC Hyperlinks should not be broken by wrap()#191
Merged
Conversation
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.
Codecov Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.