nano

nano with my custom patches
git clone git://bsandro.tech/nano
Log | Files | Refs | README | LICENSE

commit 86b83888891213d473ea077e2b50bdeba9171103
parent 812c48dde49249e9303605e3b1531eaeca9ada87
Author: Andy Koppe <andy.koppe@gmail.com>
Date:   Mon, 18 Sep 2023 22:20:46 +0100

rcfile: map the gray #rgb codes (#111 to #EEE) to the xterm grayscale

When the red, green and blue components of a three-digit hex #RGB code
are equal and they aren't #000 for black or #FFF for white, map them to
xterm-256color's 24-level grayscale ranging from index 232 to 255.

This means that the 14 gray levels available in #RGB codes all map to
different tones, whereas previously they mapped to only the four gray
tones available in the 6x6x6 color cube.

Signed-off-by: Andy Koppe <andy.koppe@gmail.com>

Diffstat:
Msrc/rcfile.c | 11++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/src/rcfile.c b/src/rcfile.c @@ -997,10 +997,15 @@ short closest_index_color(short red, short green, short blue) /* Translation table, from 16 intended levels to 6 available levels. */ static const short level[] = { 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5 }; - if (COLORS == 256) - return (36 * level[red] + 6 * level[green] + level[blue] + 16); - else + /* Translation table, from 14 intended gray levels to 24 available levels. */ + static const short gray[] = { 1, 2, 3, 4, 5, 6, 7, 9, 11, 13, 15, 18, 21, 23 }; + + if (COLORS != 256) return THE_DEFAULT; + else if (red == green && red == blue && red > 0 && red < 0xF) + return 232 + gray[red - 1]; + else + return (36 * level[red] + 6 * level[green] + level[blue] + 16); } #define COLORCOUNT 34