Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: What appears to be inconsistent results from ${(%):-%F{${subscript}}



Jim wrote:
> Output for the  following function will help visualize what I believe to be
> inconsistencies of the output of ${(%):-%F{${subscript}}.

The escape sequences generated for %F, %K, etc come from the system
termcap database. So the output produced by your function will vary for
different systems and terminals. This makes it difficult to understand
what it is you regard to be inconsistent. For some terminals, the
colours 0 - 255 result in consistent escape sequences running from
\e[38;5;0m through to \e[38;5;255m

Check what the AF termcap (or setab terminfo) entry is for your
terminal:
  od -a <<<$termcap[AF]
or some other terminal:
  TERM=foot zsh -c 'od -a <<<$termcap[AF]'

This string (which is processed by tparm()) may contain conditionals
and amounts to a stack based byte-code. It is not uncommon that this
interface will generate \e[32m for colour 2 (green), \e[92m for colour
10 (bright green) but \e[38;5;82m for colour 82. Perhaps this is what
you are seeing as inconsistent. The termcap/terminfo interface only
accepts a single number as the parameter for this entry.

> To my original point
>
> 1)  the color names grey and gray do not output black but output the default

grey/gray is not one of the eight original colours supported by a
terminal that supports eight colours. Terminals that support 16 colours
added 8 bright variants. bright-black and bright-white is fairly
meaningless so in practice, "white" was often somewhat off-white and
bright-black is what might be better termed "grey".

> 2) bright color names are not converted but output the default color
>     Should bright color names be added to the code?
>   As you can see in 3) the code for bright colors is there

Unrecognised values select the default color. My own opinion is that
it would be better not to try to recognise more colour names because
it'd just lead to more complaints about names not matching colours.
Also, grey has two valid spellings and "bright" amounts to technical
terminology that is only meaningful with the context of historical
terminal colours. TERM=linux may support colours 0-15 but not all
terminals do.

> 3) using decimal numbers(0-255)
>     0 - 15  uses 30-27 and 90-97(bright) instead of using the colors defined
>    by the terminal
>   NOTE: 0-15 are defined even for TERM=linux
>   16-255 uses the colors defined by the terminal
>   Is there a reason why it doesn't use the terminal colors for 0-15?

I'm suspecting from this last sentence that, in the interests of making
a wider range of colours available, your terminal is producing different
colours for different forms. So perhaps \e[92m is a bright green and
\e[38;5;10m is something else. For the termcap interface, there can only
be one colour 10. Hard coding escape sequences in zsh should be avoided
if at all possible. If you really want a wide-choice of colours, most
newer graphical terminals support true-colour. (Though some of them fake
it in the interests of keeping memory usage for the scroll-back buffer
down. And others just consume lots...)

Oliver




Messages sorted by: Reverse Date, Date, Thread, Author