4
4
#include < string>
5
5
6
6
#include < git2.h>
7
+ #include < termcolor/termcolor.hpp>
7
8
8
9
#include " status_subcommand.hpp"
9
10
#include " ../wrapper/status_wrapper.hpp"
@@ -45,16 +46,16 @@ struct status_messages
45
46
const std::map<git_status_t , status_messages> status_msg_map = // TODO : check spaces in short_mod
46
47
{
47
48
{ GIT_STATUS_CURRENT, {" " , " " } },
48
- { GIT_STATUS_INDEX_NEW, {" A " , " \t new file:" } },
49
- { GIT_STATUS_INDEX_MODIFIED, {" M " , " \t modified :" } },
50
- { GIT_STATUS_INDEX_DELETED, {" D " , " \t deleted :" } },
51
- { GIT_STATUS_INDEX_RENAMED, {" R " , " \t renamed :" } },
52
- { GIT_STATUS_INDEX_TYPECHANGE, {" T " , " \t typechange :" } },
49
+ { GIT_STATUS_INDEX_NEW, {" A " , " \t new file:" } },
50
+ { GIT_STATUS_INDEX_MODIFIED, {" M " , " \t modified :" } },
51
+ { GIT_STATUS_INDEX_DELETED, {" D " , " \t deleted :" } },
52
+ { GIT_STATUS_INDEX_RENAMED, {" R " , " \t renamed :" } },
53
+ { GIT_STATUS_INDEX_TYPECHANGE, {" T " , " \t typechange :" } },
53
54
{ GIT_STATUS_WT_NEW, {" ?? " , " " } },
54
- { GIT_STATUS_WT_MODIFIED, {" M " , " \t modified :" } },
55
- { GIT_STATUS_WT_DELETED, {" D " , " \t deleted :" } },
56
- { GIT_STATUS_WT_TYPECHANGE, {" T " , " \t typechange :" } },
57
- { GIT_STATUS_WT_RENAMED, {" R " , " \t renamed :" } },
55
+ { GIT_STATUS_WT_MODIFIED, {" M " , " \t modified :" } },
56
+ { GIT_STATUS_WT_DELETED, {" D " , " \t deleted :" } },
57
+ { GIT_STATUS_WT_TYPECHANGE, {" T " , " \t typechange :" } },
58
+ { GIT_STATUS_WT_RENAMED, {" R " , " \t renamed :" } },
58
59
{ GIT_STATUS_WT_UNREADABLE, {" " , " " } },
59
60
{ GIT_STATUS_IGNORED, {" !! " , " " } },
60
61
{ GIT_STATUS_CONFLICTED, {" " , " " } },
@@ -78,7 +79,7 @@ std::string get_print_status(git_status_t status, output_format of)
78
79
std::string entry_status;
79
80
if ((of == output_format::DEFAULT) || (of == output_format::LONG))
80
81
{
81
- entry_status = status_msg_map.at (status).long_mod + " \t " ;
82
+ entry_status = status_msg_map.at (status).long_mod + " " ;
82
83
}
83
84
else if (of == output_format::SHORT)
84
85
{
@@ -139,24 +140,31 @@ std::vector<print_entry> get_entries_to_print(git_status_t status, status_list_w
139
140
return entries_to_print;
140
141
}
141
142
142
- void print_entries (std::vector<print_entry> entries_to_print)
143
+ void print_entries (std::vector<print_entry> entries_to_print, bool is_long, stream_colour_fn colour )
143
144
{
144
145
for (auto e: entries_to_print)
145
146
{
146
- std::cout << e.status << e.item << std::endl;
147
+ if (is_long)
148
+ {
149
+ std::cout << colour << e.status << e.item << termcolor::reset << std::endl;
150
+ }
151
+ else
152
+ {
153
+ std::cout << colour << e.status << termcolor::reset << e.item << std::endl;
154
+ }
147
155
}
148
156
}
149
157
150
158
void print_not_tracked (const std::vector<print_entry>& entries_to_print, const std::set<std::string>& tracked_dir_set,
151
- std::set<std::string>& untracked_dir_set)
159
+ std::set<std::string>& untracked_dir_set, bool is_long, stream_colour_fn colour )
152
160
{
153
161
std::vector<print_entry> not_tracked_entries_to_print{};
154
162
for (auto e: entries_to_print)
155
163
{
156
164
const size_t first_slash_idx = e.item .find (' /' );
157
165
if (std::string::npos != first_slash_idx)
158
166
{
159
- auto directory = e.item .substr (0 , first_slash_idx);
167
+ auto directory = " \t " + e.item .substr (0 , first_slash_idx) + " / " ;
160
168
if (tracked_dir_set.contains (directory))
161
169
{
162
170
not_tracked_entries_to_print.push_back (e);
@@ -177,7 +185,7 @@ void print_not_tracked(const std::vector<print_entry>& entries_to_print, const s
177
185
not_tracked_entries_to_print.push_back (e);
178
186
}
179
187
}
180
- print_entries (not_tracked_entries_to_print);
188
+ print_entries (not_tracked_entries_to_print, is_long, colour );
181
189
}
182
190
183
191
void status_subcommand::run ()
@@ -220,17 +228,19 @@ void status_subcommand::run()
220
228
std::cout << " ## " << branch_name << std::endl;
221
229
}
222
230
}
231
+
223
232
if (sl.has_tobecommited_header ())
224
233
{
234
+ stream_colour_fn colour = termcolor::green;
225
235
if (is_long)
226
236
{
227
- std::cout << tobecommited_header << std::endl ;
237
+ std::cout << tobecommited_header;
228
238
}
229
- print_entries (get_entries_to_print (GIT_STATUS_INDEX_NEW, sl, true , of, &tracked_dir_set));
230
- print_entries (get_entries_to_print (GIT_STATUS_INDEX_MODIFIED, sl, true , of, &tracked_dir_set));
231
- print_entries (get_entries_to_print (GIT_STATUS_INDEX_DELETED, sl, true , of, &tracked_dir_set));
232
- print_entries (get_entries_to_print (GIT_STATUS_INDEX_RENAMED, sl, true , of, &tracked_dir_set));
233
- print_entries (get_entries_to_print (GIT_STATUS_INDEX_TYPECHANGE, sl, true , of, &tracked_dir_set));
239
+ print_entries (get_entries_to_print (GIT_STATUS_INDEX_NEW, sl, true , of, &tracked_dir_set), is_long, colour );
240
+ print_entries (get_entries_to_print (GIT_STATUS_INDEX_MODIFIED, sl, true , of, &tracked_dir_set), is_long, colour );
241
+ print_entries (get_entries_to_print (GIT_STATUS_INDEX_DELETED, sl, true , of, &tracked_dir_set), is_long, colour );
242
+ print_entries (get_entries_to_print (GIT_STATUS_INDEX_RENAMED, sl, true , of, &tracked_dir_set), is_long, colour );
243
+ print_entries (get_entries_to_print (GIT_STATUS_INDEX_TYPECHANGE, sl, true , of, &tracked_dir_set), is_long, colour );
234
244
if (is_long)
235
245
{
236
246
std::cout << std::endl;
@@ -239,44 +249,46 @@ void status_subcommand::run()
239
249
240
250
if (sl.has_notstagged_header ())
241
251
{
252
+ stream_colour_fn colour = termcolor::red;
242
253
if (is_long)
243
254
{
244
- std::cout << notstagged_header << std::endl ;
255
+ std::cout << notstagged_header;
245
256
}
246
- print_entries (get_entries_to_print (GIT_STATUS_WT_MODIFIED, sl, false , of, &tracked_dir_set));
247
- print_entries (get_entries_to_print (GIT_STATUS_WT_DELETED, sl, false , of, &tracked_dir_set));
248
- print_entries (get_entries_to_print (GIT_STATUS_WT_TYPECHANGE, sl, false , of, &tracked_dir_set));
249
- print_entries (get_entries_to_print (GIT_STATUS_WT_RENAMED, sl, false , of, &tracked_dir_set));
257
+ print_entries (get_entries_to_print (GIT_STATUS_WT_MODIFIED, sl, false , of, &tracked_dir_set), is_long, colour );
258
+ print_entries (get_entries_to_print (GIT_STATUS_WT_DELETED, sl, false , of, &tracked_dir_set), is_long, colour );
259
+ print_entries (get_entries_to_print (GIT_STATUS_WT_TYPECHANGE, sl, false , of, &tracked_dir_set), is_long, colour );
260
+ print_entries (get_entries_to_print (GIT_STATUS_WT_RENAMED, sl, false , of, &tracked_dir_set), is_long, colour );
250
261
if (is_long)
251
262
{
252
263
std::cout << std::endl;
253
264
}
254
265
}
255
266
256
-
257
267
if (sl.has_untracked_header ())
258
268
{
269
+ stream_colour_fn colour = termcolor::red;
259
270
if (is_long)
260
271
{
261
- std::cout << untracked_header << std::endl ;
272
+ std::cout << untracked_header;
262
273
}
263
- print_not_tracked (get_entries_to_print (GIT_STATUS_WT_NEW, sl, false , of), tracked_dir_set, untracked_dir_set);
274
+ print_not_tracked (get_entries_to_print (GIT_STATUS_WT_NEW, sl, false , of), tracked_dir_set, untracked_dir_set, is_long, colour );
264
275
if (is_long)
265
276
{
266
277
std::cout << std::endl;
267
278
}
268
279
}
269
280
270
- if (sl.has_ignored_header ())
271
- {
272
- if (is_long)
273
- {
274
- std::cout << ignored_header << std::endl;
275
- }
276
- print_not_tracked (get_entries_to_print (GIT_STATUS_IGNORED, sl, false , of), tracked_dir_set, untracked_dir_set);
277
- if (is_long)
278
- {
279
- std::cout << std::endl;
280
- }
281
- }
281
+ // if (sl.has_ignored_header())
282
+ // {
283
+ // stream_colour_fn colour = termcolor::red;
284
+ // if (is_long)
285
+ // {
286
+ // std::cout << ignored_header;
287
+ // }
288
+ // print_not_tracked(get_entries_to_print(GIT_STATUS_IGNORED, sl, false, of), tracked_dir_set, untracked_dir_set, is_long, colour);
289
+ // if (is_long)
290
+ // {
291
+ // std::cout << std::endl;
292
+ // }
293
+ // }
282
294
}
0 commit comments