@@ -12,6 +12,9 @@ struct add_i_state {
12
12
int use_color ;
13
13
char header_color [COLOR_MAXLEN ];
14
14
char help_color [COLOR_MAXLEN ];
15
+ char prompt_color [COLOR_MAXLEN ];
16
+ char error_color [COLOR_MAXLEN ];
17
+ char reset_color [COLOR_MAXLEN ];
15
18
};
16
19
17
20
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)
45
48
46
49
init_color (r , s , "header" , s -> header_color , GIT_COLOR_BOLD );
47
50
init_color (r , s , "help" , s -> help_color , GIT_COLOR_BOLD_RED );
51
+ init_color (r , s , "prompt" , s -> prompt_color , GIT_COLOR_BOLD_BLUE );
52
+ init_color (r , s , "error" , s -> error_color , GIT_COLOR_BOLD_RED );
53
+ init_color (r , s , "reset" , s -> reset_color , GIT_COLOR_RESET );
48
54
}
49
55
50
56
/*
@@ -240,7 +246,8 @@ static ssize_t list_and_choose(struct add_i_state *s,
240
246
241
247
list (s , & items -> items , & opts -> list_opts );
242
248
243
- printf ("%s%s" , opts -> prompt , "> " );
249
+ color_fprintf (stdout , s -> prompt_color , "%s" , opts -> prompt );
250
+ fputs ("> " , stdout );
244
251
fflush (stdout );
245
252
246
253
if (strbuf_getline (& input , stdin ) == EOF ) {
@@ -283,7 +290,8 @@ static ssize_t list_and_choose(struct add_i_state *s,
283
290
index = find_unique (p , items );
284
291
285
292
if (index < 0 || index >= items -> items .nr )
286
- printf (_ ("Huh (%s)?\n" ), p );
293
+ color_fprintf_ln (stdout , s -> error_color ,
294
+ _ ("Huh (%s)?" ), p );
287
295
else {
288
296
res = index ;
289
297
break ;
@@ -506,18 +514,23 @@ struct command_item {
506
514
command_t command ;
507
515
};
508
516
517
+ struct print_command_item_data {
518
+ const char * color , * reset ;
519
+ };
520
+
509
521
static void print_command_item (int i , struct string_list_item * item ,
510
522
void * print_command_item_data )
511
523
{
524
+ struct print_command_item_data * d = print_command_item_data ;
512
525
struct command_item * util = item -> util ;
513
526
514
527
if (!util -> prefix_length ||
515
528
!is_valid_prefix (item -> string , util -> prefix_length ))
516
529
printf (" %2d: %s" , i + 1 , item -> string );
517
530
else
518
- printf (" %2d: [% .*s] %s" , i + 1 ,
519
- (int )util -> prefix_length , item -> string ,
520
- item -> string + util -> prefix_length );
531
+ printf (" %2d: %s% .*s%s %s" , i + 1 ,
532
+ d -> color , (int )util -> prefix_length , item -> string ,
533
+ d -> reset , item -> string + util -> prefix_length );
521
534
}
522
535
523
536
static void command_prompt_help (struct add_i_state * s )
@@ -535,8 +548,9 @@ static void command_prompt_help(struct add_i_state *s)
535
548
int run_add_i (struct repository * r , const struct pathspec * ps )
536
549
{
537
550
struct add_i_state s = { NULL };
551
+ struct print_command_item_data data = { "[" , "]" };
538
552
struct list_and_choose_options main_loop_opts = {
539
- { 4 , N_ ("*** Commands ***" ), print_command_item , NULL },
553
+ { 4 , N_ ("*** Commands ***" ), print_command_item , & data },
540
554
N_ ("What now" ), command_prompt_help
541
555
};
542
556
struct {
@@ -567,6 +581,15 @@ int run_add_i(struct repository *r, const struct pathspec *ps)
567
581
568
582
init_add_i_state (& s , r );
569
583
584
+ /*
585
+ * When color was asked for, use the prompt color for
586
+ * highlighting, otherwise use square brackets.
587
+ */
588
+ if (s .use_color ) {
589
+ data .color = s .prompt_color ;
590
+ data .reset = s .reset_color ;
591
+ }
592
+
570
593
strbuf_addstr (& header , " " );
571
594
strbuf_addf (& header , print_file_item_data .modified_fmt ,
572
595
_ ("staged" ), _ ("unstaged" ), _ ("path" ));
0 commit comments