diff options
author | Oliver Kiddle <okiddle@yahoo.co.uk> | 2018-11-05 22:24:05 +0100 |
---|---|---|
committer | Oliver Kiddle <okiddle@yahoo.co.uk> | 2018-11-05 22:24:05 +0100 |
commit | 37d0005a9e651f366076c930019464d162506a57 (patch) | |
tree | 11af20db3184af2a860791a9014e3b474de957a1 /Src/prompt.c | |
parent | 916ba78cd7c30800e7025bb91e735e27320fff29 (diff) | |
download | zsh-37d0005a9e651f366076c930019464d162506a57.tar.gz zsh-37d0005a9e651f366076c930019464d162506a57.tar.xz zsh-37d0005a9e651f366076c930019464d162506a57.zip |
43747: new module to map colours from hex triplets to the nearest matching colour
Diffstat (limited to 'Src/prompt.c')
-rw-r--r-- | Src/prompt.c | 19 |
1 files changed, 18 insertions, 1 deletions
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 */ |