Skip to content

Round Text Highlighting

This PR provides a new escape code for rounded text highlighting!

Here are some photos: image image

Use

The new escape code works just like any SGR/CSI escape code. An example is:

\e[48:5:2m\e[108:1:15mRound\e[109m\e[48:5:1mRectangle\e[0m

The code \e[108:_:_m sets corner flags. The code \e[109m clears all corner flags, but you can also use \e[108:0:0m or \e[0m.

Synatx

The syntax is as follows:

\e[108:<overlap mode>:<corner flags>m.

The <style flags> changes how corners render when they touch. The <corner flags> is a decimal 4-bit flag that selects each corner to round. }

Corner Flags

corner_bits

Each corner is represented by a bit in a 4-bit bit flag. We use the decimal representation of this bit flag for simplicity. Each bit is counted counter-clockwise from the top right corner. This means that 1 represents the top right corner and 8 represents the bottom right corner. So, if you set <corner flags> to 15 you will round each corner because it is the sum of 1, 2, 4, and 8.

Style Flags

image

Round corners create tiny gaps of dead space when they touch regular corners. We can "overlap" part of a regular corner behind a round corner to remove this dead space. Users can select the behavior they want as part of the escape code. This field could also support any future extensions to text highlighting. In the future something like \e[108:3:15m could render VS Code like highlights.

Mode 0 - No Overlap

Round highlights will be rendered but will not overlap neighboring highlights. This leaves blank spaces when round corners meet regular corners.

Mode 1 - Round Overlap

If a round corner touches a regular corner it will "overlap" with it. The mode of the round corner controls this behavior. So, nothing will happen if a mode 0 round corner touches a mode 1 regular corner. Only if a mode 1 round corner touches a regular corner will overlap happen.

Mode <a number greater than 1>

Reserved for future use!

Future Work

This PR introduces even more complexity into already overly complex bits of code. More work could be done to make ExtraFlags behave more like RenditionFlags. There might be some performance gains to be had. The cursor looks a bit funny when it is over a rounded highlight. Add more "style flags" for things like multiline highlights.

Edited by Kaleb Wells

Merge request reports