Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed: Implement colon separated CSI parameters #4154

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

fornwall
Copy link
Member

Colon separated escape sequences for setting colors

It seems that more and more terminal emulators and terminal programs supports colon (:) as well as semicolon (;) to specify colors:

red=255 green=100 blue=0 
printf "\x1b[38;2;${red};${green};${blue}m TRUECOLOR\n" # Semicolon separated, works in Termux
printf "\x1b[38:2:${red}:${green}:${blue}m TRUECOLOR\n" # Colon separated, implemented in this PR

See https://github.com/termstandard/colors?tab=readme-ov-file#truecolor-support-in-output-devices, where it can be seen that multiple terminal emulators also support using a colon as delimiter nowadays:

This is now implemented in Termux as well. Fixes termux/termux-packages#20655, escape sequence issues with vtm.

See alacritty/vte#22 for a discussion when this was implemented in alacritty/vte.

Colored and styled underlines parsing

We also here start to parse Colored and styled underlines as initially proposed by Kitty:

To set the underline style:

[4:0m # no underline
[4:1m # straight underline
[4:2m # double underline
[4:3m # curly underline
[4:4m # dotted underline
[4:5m # dashed underline
[4m # straight underline (for backwards compat)
[24m # no underline (for backwards compat)

To set the underline color (this is reserved and as far as I can tell not actually used for anything):

[58...m
This works exactly like the codes 38, 48 that are used to set foreground and background color respectively.

To reset the underline color (also previously reserved and unused):
[59m

In this initial step we currently don't support straight/double/curly/dotted/dashed nor colored underlines, but parse them and map them to normal underlines. Fixes termux/termux-packages#20620, escape sequences showing up at the start of neovim. Future follow up work is actually respecting them when rendering, which is (at least IMHO) a nice touch when using code editors with support for it such as neovim.

@fornwall fornwall force-pushed the colon-separated-csi-parameters branch from 7b0a492 to 98e98c0 Compare September 17, 2024 15:44
@fornwall fornwall force-pushed the colon-separated-csi-parameters branch from 98e98c0 to 9a8dcd0 Compare September 18, 2024 20:43
@@ -212,21 +217,21 @@ public void testSelectGraphics() {
enterString(("\033[0m")); // Reset fg and bg colors.
assertEquals(TextStyle.COLOR_INDEX_FOREGROUND, mTerminal.mForeColor);
assertEquals(TextStyle.COLOR_INDEX_BACKGROUND, mTerminal.mBackColor);
enterString("\033[38;2;255;127;2;48;2;1;2;254m");
enterString("\033[38;2;255;127;2;48;2;1;2;254m".replace(';', separator));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't want to replace all semicolons with colons. Having all separators be colon would in all other terminal emulators (at least the 6 I tested) only set the foreground color. Instead you want the separator between the colors to remain a semicolon. So these are the two cases you want to test, which should both render as orange text on blue background:

\033[38;2;255;127;2;48;2;1;2;254m
\033[38:2:255:127:2;48:2:1:2:254m

I haven't tested this code, but if the one with all colons (\033[38:2:255:127:2:48:2:1:2:254m) renders the same as the one with semicolons here, note that this is different behavior from other terminal emulators.

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.

[Bug]: escape sequence issues with vtm [Bug]: Strange behavior of neovim after update
2 participants