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

Many CSI sequences are ignored (discarded) in a prompt #1836

Open
1 task done
lewis-yeung opened this issue Sep 1, 2024 · 1 comment
Open
1 task done

Many CSI sequences are ignored (discarded) in a prompt #1836

lewis-yeung opened this issue Sep 1, 2024 · 1 comment

Comments

@lewis-yeung
Copy link

What happened, and what did you expect to happen?

We know that Elvish parses CSI sequences in a prompt into Text objects instead of writing raw output. It's cool, though introducing a defect. There are many CSI sequences (e.g., a \x1b[21m sequence that typically means disabling bold intensity text style on several terminals) being ignored (discarded) during the parsing via ui.ParseSGREscapedText. However, prompt engines like Oh My Posh, depend on utilizing these control sequences to construct flexible and awesome prompts. The drawback leads to incomplete or unexpected styled text rendered on a terminal.

Output of "elvish -version"

0.21.0+official

Code of Conduct

@krader1961
Copy link
Contributor

FWIW, the relevant code is ui.StylingFromSGR that is invoked by ui.ParseSGREscapedText

Notice that quite a few of the SGR parameters documented at Wikipedia ANSI SGR parameters, including 21, are not handled by that function. Some of the known SGR parameters can be ignored because they are unlikely to ever be relevant for Elvish; e.g., 20, 26, 50, etc. It's also not clear how to support some parameters, such as 11 thru 19 which select an alternative font, but it seems unlikely those SGR parameters need to be supported by Elvish.

SGR parameter 21 (the focus of this issue) is interesting in that its official meaning (double-underline) is different from its de-facto meaning (disable bold intensity). But there is a more general issue since none of the negative SGR parameters are currently supported. For example, 22 (not bold or faint intensity), 23 (not italic), 24 (not underlined), etc. are also not currently supported by Elvish. But it should be straightforward to enhance ui.StylingFromSGR to support the negative parameters since the core Elvish text styling code supports the concept. See

elvish/pkg/ui/styling.go

Lines 91 to 96 in ce19c91

NoBold Styling = boolOff{boldField{}}
NoDim Styling = boolOff{dimField{}}
NoItalic Styling = boolOff{italicField{}}
NoUnderlined Styling = boolOff{underlinedField{}}
NoBlink Styling = boolOff{blinkField{}}
NoInverse Styling = boolOff{inverseField{}}

Here is an example:

> put (styled b bold) (styled (styled x bold red) no-bold)
▶ (ui:text (ui:text-segment b &bold=$true))
▶ (ui:text (ui:text-segment x &fg-color=red))

Someone just needs to write the code and add appropriate unit tests. It might also be useful if a command similar to styled was added that allows Elvish programs to explicitly convert strings containing SGR sequences to styled sequences. If nothing else that would make interactive testing easier of how SGR sequences are converted implicitly by the Elvish prompt code.

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

No branches or pull requests

2 participants