aboutsummaryrefslogtreecommitdiffstats
path: root/add-interactive.c
diff options
context:
space:
mode:
authorSlavica Đukić <slawica92@hotmail.com>2019-11-15 11:11:19 +0000
committerJunio C Hamano <gitster@pobox.com>2019-11-18 11:18:30 +0900
commit3d965c76744482b50669a7d1b445c0ddbf92209a (patch)
tree355d90ef1a463718e3ec18cc5128b97e466b1da0 /add-interactive.c
parent68db1cbf8eb412e81ff84b18f6c2ab8d15df99c7 (diff)
downloadgit-3d965c76744482b50669a7d1b445c0ddbf92209a.tar.gz
built-in add -i: use color in the main loop
The error messages as well as the unique prefixes are colored in `git add -i` by default; We need to do the same in the built-in version. 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.c35
1 files changed, 29 insertions, 6 deletions
diff --git a/add-interactive.c b/add-interactive.c
index 0a03b9017d..170a5800e3 100644
--- a/add-interactive.c
+++ b/add-interactive.c
@@ -12,6 +12,9 @@ struct add_i_state {
int use_color;
char header_color[COLOR_MAXLEN];
char help_color[COLOR_MAXLEN];
+ char prompt_color[COLOR_MAXLEN];
+ char error_color[COLOR_MAXLEN];
+ char reset_color[COLOR_MAXLEN];
};
static void init_color(struct repository *r, struct add_i_state *s,
@@ -45,6 +48,9 @@ static void init_add_i_state(struct add_i_state *s, struct repository *r)
init_color(r, s, "header", s->header_color, GIT_COLOR_BOLD);
init_color(r, s, "help", s->help_color, GIT_COLOR_BOLD_RED);
+ init_color(r, s, "prompt", s->prompt_color, GIT_COLOR_BOLD_BLUE);
+ init_color(r, s, "error", s->error_color, GIT_COLOR_BOLD_RED);
+ init_color(r, s, "reset", s->reset_color, GIT_COLOR_RESET);
}
/*
@@ -240,7 +246,8 @@ static ssize_t list_and_choose(struct add_i_state *s,
list(s, &items->items, &opts->list_opts);
- printf("%s%s", opts->prompt, "> ");
+ color_fprintf(stdout, s->prompt_color, "%s", opts->prompt);
+ fputs("> ", stdout);
fflush(stdout);
if (strbuf_getline(&input, stdin) == EOF) {
@@ -283,7 +290,8 @@ static ssize_t list_and_choose(struct add_i_state *s,
index = find_unique(p, items);
if (index < 0 || index >= items->items.nr)
- printf(_("Huh (%s)?\n"), p);
+ color_fprintf_ln(stdout, s->error_color,
+ _("Huh (%s)?"), p);
else {
res = index;
break;
@@ -509,18 +517,23 @@ struct command_item {
command_t command;
};
+struct print_command_item_data {
+ const char *color, *reset;
+};
+
static void print_command_item(int i, struct string_list_item *item,
void *print_command_item_data)
{
+ struct print_command_item_data *d = print_command_item_data;
struct command_item *util = item->util;
if (!util->prefix_length ||
!is_valid_prefix(item->string, util->prefix_length))
printf(" %2d: %s", i + 1, item->string);
else
- printf(" %2d: [%.*s]%s", i + 1,
- (int)util->prefix_length, item->string,
- item->string + util->prefix_length);
+ printf(" %2d: %s%.*s%s%s", i + 1,
+ d->color, (int)util->prefix_length, item->string,
+ d->reset, item->string + util->prefix_length);
}
static void command_prompt_help(struct add_i_state *s)
@@ -538,8 +551,9 @@ static void command_prompt_help(struct add_i_state *s)
int run_add_i(struct repository *r, const struct pathspec *ps)
{
struct add_i_state s = { NULL };
+ struct print_command_item_data data = { "[", "]" };
struct list_and_choose_options main_loop_opts = {
- { 4, N_("*** Commands ***"), print_command_item, NULL },
+ { 4, N_("*** Commands ***"), print_command_item, &data },
N_("What now"), command_prompt_help
};
struct {
@@ -570,6 +584,15 @@ int run_add_i(struct repository *r, const struct pathspec *ps)
init_add_i_state(&s, r);
+ /*
+ * When color was asked for, use the prompt color for
+ * highlighting, otherwise use square brackets.
+ */
+ if (s.use_color) {
+ data.color = s.prompt_color;
+ data.reset = s.reset_color;
+ }
+
strbuf_addstr(&header, " ");
strbuf_addf(&header, print_file_item_data.modified_fmt,
_("staged"), _("unstaged"), _("path"));