Add RawText markup support for escape sequences with safe width and search handling#370
Open
thehunmonkgroup wants to merge 1 commit into2.xfrom
Open
Add RawText markup support for escape sequences with safe width and search handling#370thehunmonkgroup wants to merge 1 commit into2.xfrom
thehunmonkgroup wants to merge 1 commit into2.xfrom
Conversation
### Motivation - Allow markup to carry raw byte sequences (escape sequences) so formatters can inject them without affecting visible text layout. - Ensure width calculations ignore injected raw bytes so column sizing remains correct when raw sequences are present. - Make search and string-reconstruction robust to mixed unicode/byte/tuple markup so searches do not match or break on raw bytes. ### Description - Add `vit/markup.py` with a frozen `RawText` dataclass and helper functions: `markup_contains_raw`, `markup_to_bytes`, `normalize_markup`, `markup_display_width`, and `markup_to_str`. - Normalize markup in `TaskTable.build_row_column` by calling `normalize_markup` and compute column widths via `markup_display_width` rather than naive `unicode_len`. - Update `Application.reconstitute_markup_element_as_string` to use `markup_to_str` so search string reconstruction safely handles byte/raw markup. ### Testing - Ran small Python introspection checks including `urwid.util.decompose_tagmarkup([(None, b'foo'), b'bar'])` which returned `(b'foobar', [])`, indicating byte-markup handling behaves as expected (succeeded). - Inspected `TextCanvas` and `StandardTextLayout` source via quick REPL scripts to verify layout/width helpers are available (succeeded). - No full unit test suite or integration tests were run for this change.
|
👍 |
Member
Author
|
Codex did not provide a sufficient implementation of this feature, in particular the I don't plan on working this PR any further, but leaving it open in case anyone wants to take a crack at it. |
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.
Motivation
This change introduces a small, generic markup layer so VIT can carry raw terminal escape sequences (like OSC‑8 hyperlinks) without corrupting them or letting them affect layout sizing. That makes it possible for custom formatters to inject clickable links in supported terminals (e.g., WezTerm) while keeping column widths and search behavior stable.
What Changed
New
vit/markup.pyhelper module with:RawText— a tiny wrapper for raw byte sequences (e.g., OSC‑8)normalize_markup()— converts markup containing RawText into byte-safe markup for urwidmarkup_display_width()— computes visible width while ignoring RawTextmarkup_to_str()— reconstructs a search-safe string from markup, ignoring RawTextTask table rendering now normalizes markup and uses
markup_display_width()for column sizing.Search string reconstruction is now robust to mixed str/bytes/RawText markup.
Why This Matters
Before this, any control sequence embedded in a description would be encoded with replacement by urwid, producing
?]8;;...instead of a real hyperlink. By exposing aRawTextcontainer, formatter authors can inject raw OSC‑8 sequences safely without breaking layout or search.Example: Custom Description Formatter with OSC‑8 Links
Below is a minimal example formatter that turns Jira-style prefixes into clickable terminal hyperlinks. Save as
~/.vit/formatters/description.py:NOTE: The code changes and example code were generated by Codex. I did review the code that would be committed to VIT, and it seems solid, however, I did not verify the example override, or if the code added to VIT would work as expected -- this will need to be verified by someone prior to merge