summaryrefslogtreecommitdiff
path: root/color.c
diff options
context:
space:
mode:
authorRobert Estelle <robertestelle@gmail.com>2021-10-25 22:32:36 (GMT)
committerJunio C Hamano <gitster@pobox.com>2021-10-28 16:37:08 (GMT)
commit05f1f41c9b02b916a5f03c5658bec3270ac3684d (patch)
tree1f56c22fefc92aca90f426a61c7505a144a05976 /color.c
parentaeefc1866c7f98ac76aac66b92cc142b8135054e (diff)
downloadgit-05f1f41c9b02b916a5f03c5658bec3270ac3684d.zip
git-05f1f41c9b02b916a5f03c5658bec3270ac3684d.tar.gz
git-05f1f41c9b02b916a5f03c5658bec3270ac3684d.tar.bz2
color: support "default" to restore fg/bg color
The name "default" can now be used in foreground or background colors, and means to use the terminal's default color, discarding any explicitly-set color without affecting the other attributes. On many modern terminals, this is *not* the same as specifying "white" or "black". Although attributes could previously be cleared like "no-bold", there had not been a similar mechanism available for colors, other than a full "reset", which cannot currently be combined with other settings. Note that this is *not* the same as the existing name "normal", which is a no-op placeholder to permit setting the background without changing the foreground. (i.e. what is currently called "normal" might have been more descriptively named "inherit", "none", "pass" or similar). Signed-off-by: Robert Estelle <robertestelle@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'color.c')
-rw-r--r--color.c23
1 files changed, 22 insertions, 1 deletions
diff --git a/color.c b/color.c
index 64f52a4..a5fa9b7 100644
--- a/color.c
+++ b/color.c
@@ -40,7 +40,7 @@ struct color {
enum {
COLOR_UNSPECIFIED = 0,
COLOR_NORMAL,
- COLOR_ANSI, /* basic 0-7 ANSI colors */
+ COLOR_ANSI, /* basic 0-7 ANSI colors + "default" (value = 9) */
COLOR_256,
COLOR_RGB
} type;
@@ -83,6 +83,27 @@ static int parse_ansi_color(struct color *out, const char *name, int len)
int i;
int color_offset = COLOR_FOREGROUND_ANSI;
+ if (match_word(name, len, "default")) {
+ /*
+ * Restores to the terminal's default color, which may not be
+ * the same as explicitly setting "white" or "black".
+ *
+ * ECMA-48 - Control Functions \
+ * for Coded Character Sets, 5th edition (June 1991):
+ * > 39 default display colour (implementation-defined)
+ * > 49 default background colour (implementation-defined)
+ *
+ * Although not supported /everywhere/--according to terminfo,
+ * some terminals define "op" (original pair) as a blunt
+ * "set to white on black", or even "send full SGR reset"--
+ * it's standard and well-supported enough that if a user
+ * asks for it in their config this will do the right thing.
+ */
+ out->type = COLOR_ANSI;
+ out->value = 9 + color_offset;
+ return 0;
+ }
+
if (strncasecmp(name, "bright", 6) == 0) {
color_offset = COLOR_FOREGROUND_BRIGHT_ANSI;
name += 6;