summaryrefslogtreecommitdiff
path: root/add-interactive.c
diff options
context:
space:
mode:
authorSlavica Đukić <slawica92@hotmail.com>2019-11-13 12:41:00 +0000
committerJunio C Hamano <gitster@pobox.com>2019-11-14 11:10:04 +0900
commit1daaebcaa55b43198f3e91135e738fc9e06ec549 (patch)
treec1829a6b1e11d234789be37d1d9b5070de6ee5ce /add-interactive.c
parent5e82b9e4d2bac376a817b2b48849ec061c137e49 (diff)
downloadgit-1daaebcaa55b43198f3e91135e738fc9e06ec549.tar.gz
built-in add -i: color the header in the `status` command
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@gmail.com> Signed-off-by: Slavica Đukić <slawica92@hotmail.com> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'add-interactive.c')
-rw-r--r--add-interactive.c41
1 files changed, 37 insertions, 4 deletions
diff --git a/add-interactive.c b/add-interactive.c
index aa35184d87..174e07ce83 100644
--- a/add-interactive.c
+++ b/add-interactive.c
@@ -1,5 +1,7 @@
#include "cache.h"
#include "add-interactive.h"
+#include "color.h"
+#include "config.h"
#include "diffcore.h"
#include "revision.h"
#include "refs.h"
@@ -7,11 +9,40 @@
struct add_i_state {
struct repository *r;
+ int use_color;
+ char header_color[COLOR_MAXLEN];
};
+static void init_color(struct repository *r, struct add_i_state *s,
+ const char *slot_name, char *dst,
+ const char *default_color)
+{
+ char *key = xstrfmt("color.interactive.%s", slot_name);
+ const char *value;
+
+ if (!s->use_color)
+ dst[0] = '\0';
+ else if (repo_config_get_value(r, key, &value) ||
+ color_parse(value, dst))
+ strlcpy(dst, default_color, COLOR_MAXLEN);
+
+ free(key);
+}
+
static void init_add_i_state(struct add_i_state *s, struct repository *r)
{
- s->r = r;
+ const char *value;
+
+ s->r = r;
+
+ if (repo_config_get_value(r, "color.interactive", &value))
+ s->use_color = -1;
+ else
+ s->use_color =
+ git_config_colorbool("color.interactive", value);
+ s->use_color = want_color(s->use_color);
+
+ init_color(r, s, "header", s->header_color, GIT_COLOR_BOLD);
}
struct list_options {
@@ -20,7 +51,8 @@ struct list_options {
void *print_item_data;
};
-static void list(struct string_list *list, struct list_options *opts)
+static void list(struct add_i_state *s, struct string_list *list,
+ struct list_options *opts)
{
int i;
@@ -28,7 +60,8 @@ static void list(struct string_list *list, struct list_options *opts)
return;
if (opts->header)
- printf("%s\n", opts->header);
+ color_fprintf_ln(stdout, s->header_color,
+ "%s", opts->header);
for (i = 0; i < list->nr; i++) {
opts->print_item(i, list->items + i, opts->print_item_data);
@@ -213,7 +246,7 @@ static int run_status(struct add_i_state *s, const struct pathspec *ps,
if (get_modified_files(s->r, files, ps) < 0)
return -1;
- list(files, opts);
+ list(s, files, opts);
putchar('\n');
return 0;