Support for terminal color escape codes
chrisgrieser opened this issue ยท 17 comments
Request for additional color space
not sure whether it counts as a "color space", but there are the terminal color escape codes, which control the color of output on terminals (e.g. \u001b[34m
for blue)
here is a good blogpost detailing how they work: https://www.lihaoyi.com/post/BuildyourownCommandLinewithANSIescapecodes.html
As far as I can tell, there are multiple implementations (8 colors, 16 colors, 256 colors), though I think the 16 colors cover most use cases already. Color highlighting could take into account whether it's a foreground or a background escape code.
Having support for color escape codes would make work on shell scripts much more convenient
Request for other features
No response
Thanks for your proposal.
Let's make your proposal clear.
Where do you think we should highlight for the string \u001b[34m blue
? If it is \u001b[34m
, then the story is simple. But if you want to color blue
, then some discussion is in order.
just \u001b[34m
of course.
Ok.
Then it's just a matter of thinking about foreground/background, which I think can be done quickly.
yep, that's exactly what I expected ๐
Done.
Please read :h ccc-option-pickers-ansi_escape
tysm ๐ฅณ
upon testing, I noticed the plugin wasn't always working. Upon doing some research, I found out that there are several notations for the escape codes.
- there are different prefixes,
\u001b
is just one of them. Another common prefix seems to be\030
. - also, after the
[
, it does also accept a1;
argument for adding bold.
so\033[34m
or\u001b[1;44m
or\033[0;34m
are all also valid terminal color escape sequences which are not picked up by ccc.nvim
there are different prefixes,
\u001b
ist just one of them. Another common prefix seems to be\030
.
I see that there are also expressions such as \e
. Is there a comprehensive list of escape expressions?
also, after the [, it does also accept a 1; argument for adding bold.
so \033[34m or \u001b[1;44m or \033[0;34m are all also valid terminal color escape sequences which are not picked up by ccc.nvim
I examined only direct color representation. I will research and fix.
Ah, I see. So the structure is that codes are lined up with a ;
delimiter between \e[
to m
.
It seems that whether 1
is bold
or bright
depends on the environment.
I heard that if the terminal follows the aixterm specification, the 90's and 100's represent bright.
I can add bold
and other attributes in highlight, what do you think I should do?
In other words, it is apparently left to us to decide whether 31;1
is red+bold
or bright red
.
hmm, such a decision would probably depend on whichever form is more common, which I really cannot assess. Maybe add it as a setting? ๐ค
Right. I can't determine that, can I?
Let's make it configurable, I'll add more arguments to AnsiEscapePicker.new().
I supported more representation. Could you test it?
The cases I have in my shell files all seem to work. Thanks!
One other thing I noticed though is that without setting your own ccc.picker.ansi_escape
, the highlighting of escape codes does not work. For ease of use, I'd suggest that the plugin should already work with some default color values for ccc.picker.ansi_escape
, so that the user does not have to set them?
Added. Now you can feel free to try it out.
Note that you will have to set up your own color scheme to match the terminal color scheme, or you will get different highlights than the actual output.
yep, everything appears to work fine. Thanks for implementing this great feature!