14
14
#include "string-list.h"
15
15
#include "quote.h"
16
16
#include "column.h"
17
+ #include "color.h"
17
18
18
19
static int force = -1 ; /* unset */
19
20
static int interactive ;
@@ -31,16 +32,82 @@ static const char *msg_skip_git_dir = N_("Skipping repository %s\n");
31
32
static const char * msg_would_skip_git_dir = N_ ("Would skip repository %s\n" );
32
33
static const char * msg_warn_remove_failed = N_ ("failed to remove %s" );
33
34
35
+ static int clean_use_color = -1 ;
36
+ static char clean_colors [][COLOR_MAXLEN ] = {
37
+ GIT_COLOR_RESET ,
38
+ GIT_COLOR_NORMAL , /* PLAIN */
39
+ GIT_COLOR_BOLD_BLUE , /* PROMPT */
40
+ GIT_COLOR_BOLD , /* HEADER */
41
+ GIT_COLOR_BOLD_RED , /* HELP */
42
+ GIT_COLOR_BOLD_RED , /* ERROR */
43
+ };
44
+ enum color_clean {
45
+ CLEAN_COLOR_RESET = 0 ,
46
+ CLEAN_COLOR_PLAIN = 1 ,
47
+ CLEAN_COLOR_PROMPT = 2 ,
48
+ CLEAN_COLOR_HEADER = 3 ,
49
+ CLEAN_COLOR_HELP = 4 ,
50
+ CLEAN_COLOR_ERROR = 5 ,
51
+ };
52
+
53
+ static int parse_clean_color_slot (const char * var )
54
+ {
55
+ if (!strcasecmp (var , "reset" ))
56
+ return CLEAN_COLOR_RESET ;
57
+ if (!strcasecmp (var , "plain" ))
58
+ return CLEAN_COLOR_PLAIN ;
59
+ if (!strcasecmp (var , "prompt" ))
60
+ return CLEAN_COLOR_PROMPT ;
61
+ if (!strcasecmp (var , "header" ))
62
+ return CLEAN_COLOR_HEADER ;
63
+ if (!strcasecmp (var , "help" ))
64
+ return CLEAN_COLOR_HELP ;
65
+ if (!strcasecmp (var , "error" ))
66
+ return CLEAN_COLOR_ERROR ;
67
+ return -1 ;
68
+ }
69
+
34
70
static int git_clean_config (const char * var , const char * value , void * cb )
35
71
{
36
72
if (!prefixcmp (var , "column." ))
37
73
return git_column_config (var , value , "clean" , & colopts );
38
74
75
+ /* honors the color.interactive* config variables which also
76
+ applied in git-add--interactive and git-stash */
77
+ if (!strcmp (var , "color.interactive" )) {
78
+ clean_use_color = git_config_colorbool (var , value );
79
+ return 0 ;
80
+ }
81
+ if (!prefixcmp (var , "color.interactive." )) {
82
+ int slot = parse_clean_color_slot (var +
83
+ strlen ("color.interactive." ));
84
+ if (slot < 0 )
85
+ return 0 ;
86
+ if (!value )
87
+ return config_error_nonbool (var );
88
+ color_parse (value , var , clean_colors [slot ]);
89
+ return 0 ;
90
+ }
91
+
39
92
if (!strcmp (var , "clean.requireforce" )) {
40
93
force = !git_config_bool (var , value );
41
94
return 0 ;
42
95
}
43
- return git_default_config (var , value , cb );
96
+
97
+ /* inspect the color.ui config variable and others */
98
+ return git_color_default_config (var , value , cb );
99
+ }
100
+
101
+ static const char * clean_get_color (enum color_clean ix )
102
+ {
103
+ if (want_color (clean_use_color ))
104
+ return clean_colors [ix ];
105
+ return "" ;
106
+ }
107
+
108
+ static void clean_print_color (enum color_clean ix )
109
+ {
110
+ printf ("%s" , clean_get_color (ix ));
44
111
}
45
112
46
113
static int exclude_cb (const struct option * opt , const char * arg , int unset )
@@ -184,14 +251,18 @@ static void interactive_main_loop(void)
184
251
185
252
while (del_list .nr ) {
186
253
putchar ('\n' );
254
+ clean_print_color (CLEAN_COLOR_HEADER );
187
255
printf_ln (Q_ ("Would remove the following item:" ,
188
256
"Would remove the following items:" ,
189
257
del_list .nr ));
258
+ clean_print_color (CLEAN_COLOR_RESET );
190
259
putchar ('\n' );
191
260
192
261
pretty_print_dels ();
193
262
263
+ clean_print_color (CLEAN_COLOR_PROMPT );
194
264
printf (_ ("Remove [y/n]? " ));
265
+ clean_print_color (CLEAN_COLOR_RESET );
195
266
if (strbuf_getline (& confirm , stdin , '\n' ) != EOF ) {
196
267
strbuf_trim (& confirm );
197
268
} else {
0 commit comments