From 37d0005a9e651f366076c930019464d162506a57 Mon Sep 17 00:00:00 2001 From: Oliver Kiddle Date: Mon, 5 Nov 2018 22:24:05 +0100 Subject: 43747: new module to map colours from hex triplets to the nearest matching colour --- Src/prompt.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'Src/prompt.c') diff --git a/Src/prompt.c b/Src/prompt.c index 959ed8e3d..39edbdb2b 100644 --- a/Src/prompt.c +++ b/Src/prompt.c @@ -1621,7 +1621,24 @@ match_colour(const char **teststrp, int is_fg, int colour) int shft, on, named = 0, tc; if (teststrp) { - if ((named = ialpha(**teststrp))) { + if (**teststrp == '#' && isxdigit((*teststrp)[1])) { + struct color_rgb color; + char *end; + zlong col = zstrtol(*teststrp+1, &end, 16); + if (end - *teststrp == 4) { + color.red = col >> 8 | ((col >> 8) << 4); + color.green = (col & 0xf0) >> 4; + color.green |= color.green << 4; + color.blue = col & 0xf; + color.blue |= color.blue << 4; + } else if (end - *teststrp == 7) { + color.red = col >> 16; + color.green = (col & 0xff00) >> 8; + color.blue = col & 0xff; + } + *teststrp = end; + colour = runhookdef(GETCOLORATTR, &color); + } else if ((named = ialpha(**teststrp))) { colour = match_named_colour(teststrp); if (colour == 8) { /* default */ -- cgit 1.4.1