[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Nano-devel] about support for more than 16 colors

From: Brand Huntsman
Subject: Re: [Nano-devel] about support for more than 16 colors
Date: Wed, 3 Jan 2018 17:14:42 -0700

On Wed, 3 Jan 2018 21:57:09 +1030
address@hidden wrote:

> > Is it possible for nano to query the 16/256-color palette?  
> I do think, however, that the method was very similar (if not the
> same) as the one described by a fellow called Gilles in this post on
> Stack Exchange:

The following C code does the same as `tput colors`.
    char *tc_buffer = (char *)malloc(2048);
    char *termtype = getenv("TERM");
    tgetent(tc_buffer, termtype);
    int max_colors = tgetnum("Co");

What does `tput colors` return on a 24-bit terminal? Nano could get the number 
of supported colors and warn if a palette number greater than or equal to it is 
used in a syntax. This would support 256, 88, 16 or any other number of colors.

As for 24-bit color, does ncurses even support it: . Nano 
could still use 24-bit color in syntaxes but would always need to map it to a 
palette index. So no real 24-bit color syntaxes until ncurses adds support.

The max_colors value is probably greater than 256 for 24-bit color and should 
be clamped to 256, even if ncurses supports 24-bit color. This way palette 
index isn't allowed to exceed 255. Another check would determine if ncurses has 
support for 24-bit color, even when it gets support, the system might have an 
older version installed.

If system lacks 24-bit color, output "\e]4;%d;?\a" for each index from 0 to 
max_colors-1, store result in palette table and then map 24-bit colors to 
palette. But grabbing 256 color entries would add a small delay to startup 
time, so only query the palette if the syntax uses 24-bit colors. And if that 
escape sequence returns nothing or an invalid result, stop iterating, disable 
24-bit mapping, throw an error, and don't colorize any expression that have 
24-bit color.

This could easily be added in three steps. First add "color 0-255"
support, get max_colors, check for ncurses 6.0 (pre-6.0 might only support 
16-color) and have ncurses output 88/256 colors. Then add "color rgb()|#RRGGBB" 
support, query palette and map to palette. And finally, detect ncurses support 
and output 24-bit color.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]