built-in add -p: color the prompt and the help text

... just like the Perl version ;-)

Note that this requires the `get_add_i_color()` function being defined
globally, which is the entire reason why we gave it such a descriptive
name in the first place.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
This commit is contained in:
Johannes Schindelin
2019-03-12 16:40:46 +01:00
parent cb941b6711
commit 9594f2143b
2 changed files with 17 additions and 4 deletions

View File

@@ -16,6 +16,15 @@ struct add_i_state {
void init_add_i_state(struct add_i_state *s, struct repository *r);
enum color_add_i {
COLOR_HEADER = 0,
COLOR_HELP,
COLOR_PROMPT,
COLOR_ERROR,
COLOR_RESET,
};
const char *get_add_i_color(enum color_add_i ix);
struct repository;
struct pathspec;
int run_add_i(struct repository *r, const struct pathspec *ps);

View File

@@ -334,9 +334,12 @@ static int patch_update_file(struct add_p_state *s)
strbuf_addstr(&s->buf, ",j");
if (hunk_index + 1 < s->hunk_nr)
strbuf_addstr(&s->buf, ",J");
printf("(%"PRIuMAX"/%"PRIuMAX") ",
(uintmax_t)hunk_index + 1, (uintmax_t)s->hunk_nr);
printf(_("Stage this hunk [y,n,a,d%s,?]? "), s->buf.buf);
color_fprintf(stdout, s->s.prompt_color,
"(%"PRIuMAX"/%"PRIuMAX") ",
(uintmax_t)hunk_index + 1, (uintmax_t)s->hunk_nr);
color_fprintf(stdout, s->s.prompt_color,
_("Stage this hunk [y,n,a,d%s,?]? "),
s->buf.buf);
fflush(stdout);
if (strbuf_getline(&s->answer, stdin) == EOF)
break;
@@ -378,7 +381,8 @@ soft_increment:
else if (undecided_next >= 0 && s->answer.buf[0] == 'j')
hunk_index = undecided_next;
else
puts(_(help_patch_text));
color_fprintf(stdout, s->s.help_color,
_(help_patch_text));
}
/* Any hunk to be used? */