@@ -13,11 +13,17 @@ static int use_color = -1;
13
13
enum color_add_i {
14
14
COLOR_HEADER = 0 ,
15
15
COLOR_HELP ,
16
+ COLOR_PROMPT ,
17
+ COLOR_ERROR ,
18
+ COLOR_RESET ,
16
19
};
17
20
18
21
static char list_colors [][COLOR_MAXLEN ] = {
19
22
GIT_COLOR_BOLD , /* Header */
20
23
GIT_COLOR_BOLD_RED , /* Help */
24
+ GIT_COLOR_BOLD_BLUE , /* Prompt */
25
+ GIT_COLOR_BOLD_RED , /* Error */
26
+ GIT_COLOR_RESET , /* Reset */
21
27
};
22
28
23
29
static const char * get_add_i_color (enum color_add_i ix )
@@ -33,6 +39,12 @@ static int parse_color_slot(const char *slot)
33
39
return COLOR_HEADER ;
34
40
if (!strcasecmp (slot , "help" ))
35
41
return COLOR_HELP ;
42
+ if (!strcasecmp (slot , "prompt" ))
43
+ return COLOR_PROMPT ;
44
+ if (!strcasecmp (slot , "error" ))
45
+ return COLOR_ERROR ;
46
+ if (!strcasecmp (slot , "reset" ))
47
+ return COLOR_RESET ;
36
48
37
49
return -1 ;
38
50
}
@@ -125,6 +137,8 @@ struct list_and_choose_options {
125
137
static ssize_t list_and_choose (struct prefix_item * * items , size_t nr ,
126
138
struct list_and_choose_options * opts )
127
139
{
140
+ const char * prompt_color = get_add_i_color (COLOR_PROMPT );
141
+ const char * error_color = get_add_i_color (COLOR_ERROR );
128
142
struct strbuf input = STRBUF_INIT ;
129
143
ssize_t res = -1 ;
130
144
@@ -137,7 +151,8 @@ static ssize_t list_and_choose(struct prefix_item **items, size_t nr,
137
151
138
152
list (items , nr , & opts -> list_opts );
139
153
140
- printf ("%s%s" , opts -> prompt , "> " );
154
+ color_fprintf (stdout , prompt_color , "%s" , opts -> prompt );
155
+ fputs ("> " , stdout );
141
156
fflush (stdout );
142
157
143
158
if (strbuf_getline (& input , stdin ) == EOF ) {
@@ -178,7 +193,8 @@ static ssize_t list_and_choose(struct prefix_item **items, size_t nr,
178
193
index = find_unique (p , items , nr );
179
194
180
195
if (index < 0 || index >= nr )
181
- printf (_ ("Huh (%s)?\n" ), p );
196
+ color_fprintf_ln (stdout , error_color ,
197
+ _ ("Huh (%s)?" ), p );
182
198
else {
183
199
res = index ;
184
200
break ;
@@ -423,15 +439,21 @@ static int run_status(struct repository *r, const struct pathspec *ps,
423
439
return 0 ;
424
440
}
425
441
442
+ struct print_command_item_data {
443
+ const char * color , * reset ;
444
+ };
445
+
426
446
static void print_command_item (int i , struct prefix_item * item ,
427
447
void * print_command_item_data )
428
448
{
449
+ struct print_command_item_data * d = print_command_item_data ;
450
+
429
451
if (!item -> prefix_length ||
430
452
!is_valid_prefix (item -> name , item -> prefix_length ))
431
453
printf (" %2d: %s" , i + 1 , item -> name );
432
454
else
433
- printf (" %3d: [% .*s] %s" , i + 1 ,
434
- (int )item -> prefix_length , item -> name ,
455
+ printf (" %2d: %s% .*s%s %s" , i + 1 ,
456
+ d -> color , (int )item -> prefix_length , item -> name , d -> reset ,
435
457
item -> name + item -> prefix_length );
436
458
}
437
459
@@ -455,8 +477,16 @@ static void command_prompt_help(void)
455
477
456
478
int run_add_i (struct repository * r , const struct pathspec * ps )
457
479
{
480
+ struct print_command_item_data data = {
481
+ /*
482
+ * When color was asked for, use the prompt color for
483
+ * highlighting, otherwise use square brackets.
484
+ */
485
+ want_color (use_color ) ? get_add_i_color (COLOR_PROMPT ) : "[" ,
486
+ want_color (use_color ) ? get_add_i_color (COLOR_RESET ) : "]"
487
+ };
458
488
struct list_and_choose_options main_loop_opts = {
459
- { 4 , N_ ("*** Commands ***" ), print_command_item , NULL },
489
+ { 4 , N_ ("*** Commands ***" ), print_command_item , & data },
460
490
N_ ("What now" ), command_prompt_help
461
491
};
462
492
struct command_item
0 commit comments