[PATCH 05/11] built-in add -i: color the header in the `status` command

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Johannes Schindelin <johannes.schindelin@xxxxxx>

For simplicity, we only implemented the `status` command without colors.
This patch starts adding color, matching what the Perl script
`git-add--interactive.perl` does.

Original-Patch-By: Daniel Ferreira <bnmvco@xxxxxxxxx>
Signed-off-by: Slavica Djukic <slawica92@xxxxxxxxxxx>
Signed-off-by: Johannes Schindelin <johannes.schindelin@xxxxxx>
---
 add-interactive.c | 51 ++++++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 48 insertions(+), 3 deletions(-)

diff --git a/add-interactive.c b/add-interactive.c
index d971b58552..79adc58321 100644
--- a/add-interactive.c
+++ b/add-interactive.c
@@ -1,13 +1,56 @@
 #include "cache.h"
 #include "add-interactive.h"
 #include "config.h"
+#include "color.h"
+#include "config.h"
 #include "diffcore.h"
 #include "revision.h"
 #include "refs.h"
 
+static int use_color = -1;
+
+enum color_add_i {
+	COLOR_HEADER = 0,
+};
+
+static char list_colors[][COLOR_MAXLEN] = {
+	GIT_COLOR_BOLD,      /* Header */
+};
+
+static const char *get_add_i_color(enum color_add_i ix)
+{
+	if (want_color(use_color))
+		return list_colors[ix];
+	return "";
+}
+
+static int parse_color_slot(const char *slot)
+{
+	if (!strcasecmp(slot, "header"))
+		return COLOR_HEADER;
+
+	return -1;
+}
+
 int add_i_config(const char *var, const char *value, void *cb)
 {
-	return git_default_config(var, value, cb);
+	const char *name;
+
+	if (!strcmp(var, "color.interactive")) {
+		use_color = git_config_colorbool(var, value);
+		return 0;
+	}
+
+	if (skip_prefix(var, "color.interactive.", &name)) {
+		int slot = parse_color_slot(name);
+		if (slot < 0)
+			return 0;
+		if (!value)
+			return config_error_nonbool(var);
+		return color_parse(value, list_colors[slot]);
+	}
+
+	return git_color_default_config(var, value, cb);
 }
 
 struct item {
@@ -27,8 +70,10 @@ static void list(struct item **list, size_t nr, struct list_options *opts)
 	if (!nr)
 		return;
 
-	if (opts->header)
-		printf("%s\n", opts->header);
+	if (opts->header) {
+		const char *header_color = get_add_i_color(COLOR_HEADER);
+		color_fprintf_ln(stdout, header_color, "%s", opts->header);
+	}
 
 	for (i = 0; i < nr; i++) {
 		opts->print_item(i, list[i], opts->print_item_data);
-- 
gitgitgadget




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux