Skip to content

Commit 2c723cb

Browse files
committed
built-in add -i: support ? (prompt help)
With this change, we print out the same colored help text that the Perl-based `git add -i` prints in the main loop when question mark is entered. Signed-off-by: Johannes Schindelin <[email protected]>
1 parent dd250c7 commit 2c723cb

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

add-interactive.c

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ struct add_i_state {
1111
struct repository *r;
1212
int use_color;
1313
char header_color[COLOR_MAXLEN];
14+
char help_color[COLOR_MAXLEN];
1415
};
1516

1617
static void init_color(struct repository *r, struct add_i_state *s,
@@ -43,6 +44,7 @@ static void init_add_i_state(struct add_i_state *s, struct repository *r)
4344
s->use_color = want_color(s->use_color);
4445

4546
init_color(r, s, "header", s->header_color, GIT_COLOR_BOLD);
47+
init_color(r, s, "help", s->help_color, GIT_COLOR_BOLD_RED);
4648
}
4749

4850
/*
@@ -210,6 +212,7 @@ struct list_and_choose_options {
210212
struct list_options list_opts;
211213

212214
const char *prompt;
215+
void (*print_help)(struct add_i_state *s);
213216
};
214217

215218
#define LIST_AND_CHOOSE_ERROR (-1)
@@ -250,6 +253,11 @@ static ssize_t list_and_choose(struct add_i_state *s,
250253
if (!input.len)
251254
break;
252255

256+
if (!strcmp(input.buf, "?")) {
257+
opts->print_help(s);
258+
continue;
259+
}
260+
253261
p = input.buf;
254262
for (;;) {
255263
size_t sep = strcspn(p, " \t\r\n,");
@@ -513,12 +521,24 @@ static void print_command_item(int i, struct string_list_item *item,
513521
item->string + util->prefix_length);
514522
}
515523

524+
static void command_prompt_help(struct add_i_state *s)
525+
{
526+
const char *help_color = s->help_color;
527+
color_fprintf_ln(stdout, help_color, "%s", _("Prompt help:"));
528+
color_fprintf_ln(stdout, help_color, "1 - %s",
529+
_("select a numbered item"));
530+
color_fprintf_ln(stdout, help_color, "foo - %s",
531+
_("select item based on unique prefix"));
532+
color_fprintf_ln(stdout, help_color, " - %s",
533+
_("(empty) select nothing"));
534+
}
535+
516536
int run_add_i(struct repository *r, const struct pathspec *ps)
517537
{
518538
struct add_i_state s = { NULL };
519539
struct list_and_choose_options main_loop_opts = {
520540
{ 4, N_("*** Commands ***"), print_command_item, NULL },
521-
N_("What now")
541+
N_("What now"), command_prompt_help
522542
};
523543
struct {
524544
const char *string;

0 commit comments

Comments
 (0)