1414#include "string-list.h"
1515#include "quote.h"
1616#include "column.h"
17+ #include "color.h"
1718
1819static int force = -1 ; /* unset */
1920static int interactive ;
@@ -31,16 +32,82 @@ static const char *msg_skip_git_dir = N_("Skipping repository %s\n");
3132static const char * msg_would_skip_git_dir = N_ ("Would skip repository %s\n" );
3233static const char * msg_warn_remove_failed = N_ ("failed to remove %s" );
3334
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+
3470static int git_clean_config (const char * var , const char * value , void * cb )
3571{
3672 if (!prefixcmp (var , "column." ))
3773 return git_column_config (var , value , "clean" , & colopts );
3874
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+
3992 if (!strcmp (var , "clean.requireforce" )) {
4093 force = !git_config_bool (var , value );
4194 return 0 ;
4295 }
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 ));
44111}
45112
46113static int exclude_cb (const struct option * opt , const char * arg , int unset )
@@ -184,14 +251,18 @@ static void interactive_main_loop(void)
184251
185252 while (del_list .nr ) {
186253 putchar ('\n' );
254+ clean_print_color (CLEAN_COLOR_HEADER );
187255 printf_ln (Q_ ("Would remove the following item:" ,
188256 "Would remove the following items:" ,
189257 del_list .nr ));
258+ clean_print_color (CLEAN_COLOR_RESET );
190259 putchar ('\n' );
191260
192261 pretty_print_dels ();
193262
263+ clean_print_color (CLEAN_COLOR_PROMPT );
194264 printf (_ ("Remove [y/n]? " ));
265+ clean_print_color (CLEAN_COLOR_RESET );
195266 if (strbuf_getline (& confirm , stdin , '\n' ) != EOF ) {
196267 strbuf_trim (& confirm );
197268 } else {
0 commit comments