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: Improve handling of empty ';' SGR sequences #4031

Merged
merged 1 commit into from
Aug 13, 2024
Merged

Conversation

fornwall
Copy link
Member

Currently the Termux terminal emulator prints HI in red with:

printf "\e[31;m HI \e[0m"

This is not how other terminals (tested on xterm, gnome-terminal, alacritty and the mac built in terminal) handle it, since they parse \e[31;m as \e[31;0m, where the 0 resets the colors.

This change aligns with other terminals, as well as improves performance by avoiding allocating a new int[] array for each byte processed by parseArg(), and most importantly simplifies things by removing the mIsCSIStart and mLastCSIArg state, preparing for soon supporting : separated sub parameters such as used in
https://sw.kovidgoyal.net/kitty/underlines/

Currently the Termux terminal emulator prints "HI" in red with:

```sh
printf "\e[31;m HI \e[0m"
```

This is not how other terminals (tested on xterm, gnome-terminal,
alacritty and the mac built in terminal) handle it, since they parse
""\e[31;m" as "\e[31;0m", where the "0" resets the colors.

This change aligns with other terminals, as well as improves performance
by avoiding allocating a new int[] array for each byte processed by
`parseArg()`, and most importantly simplifies things by removing the
`mIsCSIStart` and `mLastCSIArg` state, preparing for supporting ':'
separated sub parameters such as used in
https://sw.kovidgoyal.net/kitty/underlines/
@trygveaa
Copy link
Contributor

Note that WezTerm and kitty also print the text in red with this example. Reading the ECMA-48 specification (which is the one that defines this sequence) it does seem correct to reset the color, but it looks like the standard contradicts itself a bit.

Section 5.4.2 e about CSI says:

An empty parameter sub-string represents a default value which depends on the control function

And section 8.3.117 about SGR says:

Parameter default value: Ps = 0

However 5.4.2 h also says:

However, if the last parameter sub-string(s) is empty, the separator preceding it may be omitted, see B.2 in annex B.

And B.2 says:

6; 03/06 03/11 Two parameters, the first having the value 6 and the second taking the default value. NOTE - The bit combination 03/11 may be omitted (see 5.4.2 h).

So the first two quotations says that \e[31;m should be equal to \e[31;0m, but the last two quotations says it should be equal to \e[31m. However, given how this control code works \e[31;0m can't be equal to \e[31m (then it wouldn't be possible to set any colors).

@termux termux deleted a comment from MainOliver22 Jul 10, 2024
Copy link

@harveyjoey913 harveyjoey913 left a comment

Choose a reason for hiding this comment

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

👍👍

@fornwall fornwall merged commit f80b464 into master Aug 13, 2024
4 checks passed
@fornwall fornwall deleted the csi-semicolon branch August 13, 2024 17:20
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.

3 participants