Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohannes Schindelin <johannes.schindelin@gmx.de>2019-11-15 14:11:18 +0300
committerJunio C Hamano <gitster@pobox.com>2019-11-18 05:18:30 +0300
commit68db1cbf8eb412e81ff84b18f6c2ab8d15df99c7 (patch)
treea6826032138e08aa93f741c876c14dc253891626 /add-interactive.c
parent76b743234c6d122d9e194556f6f94f61493094f6 (diff)
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 <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'add-interactive.c')
-rw-r--r--add-interactive.c22
1 files changed, 21 insertions, 1 deletions
diff --git a/add-interactive.c b/add-interactive.c
index c5d95d4796..0a03b9017d 100644
--- a/add-interactive.c
+++ b/add-interactive.c
@@ -11,6 +11,7 @@ struct add_i_state {
struct repository *r;
int use_color;
char header_color[COLOR_MAXLEN];
+ char help_color[COLOR_MAXLEN];
};
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)
s->use_color = want_color(s->use_color);
init_color(r, s, "header", s->header_color, GIT_COLOR_BOLD);
+ init_color(r, s, "help", s->help_color, GIT_COLOR_BOLD_RED);
}
/*
@@ -210,6 +212,7 @@ struct list_and_choose_options {
struct list_options list_opts;
const char *prompt;
+ void (*print_help)(struct add_i_state *s);
};
#define LIST_AND_CHOOSE_ERROR (-1)
@@ -250,6 +253,11 @@ static ssize_t list_and_choose(struct add_i_state *s,
if (!input.len)
break;
+ if (!strcmp(input.buf, "?")) {
+ opts->print_help(s);
+ continue;
+ }
+
p = input.buf;
for (;;) {
size_t sep = strcspn(p, " \t\r\n,");
@@ -515,12 +523,24 @@ static void print_command_item(int i, struct string_list_item *item,
item->string + util->prefix_length);
}
+static void command_prompt_help(struct add_i_state *s)
+{
+ const char *help_color = s->help_color;
+ color_fprintf_ln(stdout, help_color, "%s", _("Prompt help:"));
+ color_fprintf_ln(stdout, help_color, "1 - %s",
+ _("select a numbered item"));
+ color_fprintf_ln(stdout, help_color, "foo - %s",
+ _("select item based on unique prefix"));
+ color_fprintf_ln(stdout, help_color, " - %s",
+ _("(empty) select nothing"));
+}
+
int run_add_i(struct repository *r, const struct pathspec *ps)
{
struct add_i_state s = { NULL };
struct list_and_choose_options main_loop_opts = {
{ 4, N_("*** Commands ***"), print_command_item, NULL },
- N_("What now")
+ N_("What now"), command_prompt_help
};
struct {
const char *string;