summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 1d28232)
raw | patch | inline | side by side (parent: 1d28232)
author | Jeff King <peff@peff.net> | |
Thu, 9 Dec 2010 17:27:08 +0000 (12:27 -0500) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Fri, 10 Dec 2010 20:59:52 +0000 (12:59 -0800) |
This gives it the same behavior as we had prior to 1d28232
(status: show branchname with a configurable color).
To do this we need the concept of a "NIL" color, which is
provided by color.[ch]. The implementation is very simple;
in particular, there are no precautions taken against code
accidentally printing the NIL. This should be fine in
practice because:
1. You can't input a NIL color in the config, so it must
come from the in-code defaults. Which means it is up
the client code to handle the NILs it defines.
2. If we do ever print a NIL, it will be obvious what the
problem is, and the bug can be fixed.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
(status: show branchname with a configurable color).
To do this we need the concept of a "NIL" color, which is
provided by color.[ch]. The implementation is very simple;
in particular, there are no precautions taken against code
accidentally printing the NIL. This should be fine in
practice because:
1. You can't input a NIL color in the config, so it must
come from the in-code defaults. Which means it is up
the client code to handle the NILs it defines.
2. If we do ever print a NIL, it will be obvious what the
problem is, and the bug can be fixed.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
color.c | patch | blob | history | |
color.h | patch | blob | history | |
wt-status.c | patch | blob | history |
index 1b00554dd50d2960b4e66f229b0d2d0da8eb8c28..6a5a54ec668e08ddef0d2f27359f3ebb3272243b 100644 (file)
--- a/color.c
+++ b/color.c
va_end(args);
return r;
}
+
+int color_is_nil(const char *c)
+{
+ return !strcmp(c, "NIL");
+}
index 03ca0647485e8044d4131f2c61c37b4e9408cd2a..170ff4074d220e7e62264c4c63d1419f4a59d664 100644 (file)
--- a/color.h
+++ b/color.h
#define GIT_COLOR_BG_MAGENTA "\033[45m"
#define GIT_COLOR_BG_CYAN "\033[46m"
+/* A special value meaning "no color selected" */
+#define GIT_COLOR_NIL "NIL"
+
/*
* This variable stores the value of color.ui
*/
__attribute__((format (printf, 3, 4)))
int color_fprintf_ln(FILE *fp, const char *color, const char *fmt, ...);
+int color_is_nil(const char *color);
+
#endif /* COLOR_H */
diff --git a/wt-status.c b/wt-status.c
index 19c9cb1d2312ad65e79dfb0aa28c182f497eb53a..ffe86b980287555ddec7b6871afe1078b5bce80c 100644 (file)
--- a/wt-status.c
+++ b/wt-status.c
GIT_COLOR_RED, /* WT_STATUS_UNMERGED */
GIT_COLOR_GREEN, /* WT_STATUS_LOCAL_BRANCH */
GIT_COLOR_RED, /* WT_STATUS_REMOTE_BRANCH */
- GIT_COLOR_NORMAL, /* WT_STATUS_ONBRANCH */
+ GIT_COLOR_NIL, /* WT_STATUS_ONBRANCH */
};
static const char *color(int slot, struct wt_status *s)
{
- return s->use_color > 0 ? s->color_palette[slot] : "";
+ const char *c = s->use_color > 0 ? s->color_palette[slot] : "";
+ if (slot == WT_STATUS_ONBRANCH && color_is_nil(c))
+ c = s->color_palette[WT_STATUS_HEADER];
+ return c;
}
void wt_status_prepare(struct wt_status *s)