Repository navigation
Draw the colours a code-block renderer prints - #3771
Merged
Merged
Conversation
Compose mode draws a code block with whatever its `renderers` command prints. Tools that draw in colour - delta, bat, chafa, a coloured plot - print ANSI escape codes, and those went into the frame as text: invisible when drawn but counted as columns, so a coloured row came out short, the frame's right rail went ragged, and a drawing made of coloured cells (an image) was garbled. Users had to pipe every tool through sed to strip the codes, losing the colour the tool was chosen for. The plugin now reads each row into its text and its styled runs: SGR codes become colours (16 colours, 256-colour and truecolor, bold, italic, underline), and every other escape code is dropped. The runs reach the screen as overlays on the row's text, which needed two editor changes: - `addConceal` takes `replacementOverlays`, styled byte ranges within the replacement. The conceal pass emits one token per run, carrying its style; a range with none is drawn as before. - A virtual line's `textOverlays` now carry `fg`, `bg` and `italic` as well as bold and underline, for drawing rows past the block's last line. A row that lands on a blank source line is still inline virtual text, which takes a single style, so it is drawn in the frame's colour; its width is right all the same. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012MC4RTeiS6hZV3vHLXYqD9
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.
Compose mode draws a code block with whatever its
rendererscommand prints. Tools that draw in colour (delta, bat, chafa, a coloured plot) print ANSI escape codes, and those went into the frame as text. The codes are invisible on screen but were counted as columns, so:What changed:
markdown_compose.ts):addConcealtakes a newreplacementOverlaysargument: styled byte ranges within the replacement text. The conceal pass emits one token per styled run, and replacements without overlays are emitted as before.textOverlaysnow carryfg,bganditalicas well asboldandunderline. They draw rows past the block's last source line.VirtualLineTextOverlayis now exported infresh.d.ts; the types and API docs were regenerated.Known limitation: a row that falls on a blank line inside the block is inline virtual text, which takes only one style. It is drawn in the frame's colour, but its width is still correct.
Tests:
New e2e test
a_tools_colours_are_drawn_and_its_escape_codes_take_no_columns. It uses a stub tool that prints red, bold truecolor green and a blue background, plus an OSC title. The test checks that:Against the old plugin it fails: the rail lands at column 95 instead of 104.
Unit tests for the styled conceal emission and the virtual-line colours.
All 171
markdown_composee2e tests pass.fmt,clippy(no new warnings) andcheck-types.share clean.I agree my contributions are licensed under GPL-3.0-or-later and may be relicensed in the future at the maintainer's discretion (see CONTRIBUTING.md).
Generated by Claude Code