/
terminal.cs
747 lines (699 loc) · 22.4 KB
/
terminal.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
//
// Authors:
// Rolf Bjarne Kvinge (rolfbjarne@gmail.com)
//
// Copyright (C) 2012 Rolf Bjarne Kvinge
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Diagnostics;
namespace gui_diff
{
class TerminalDiff : Diff
{
protected override void Run ()
{
Do ();
}
void ShowDiff (bool? staged)
{
ShowDiff (staged, false);
}
void SelectNextFile ()
{
int idx = entries.IndexOf (selected);
if (idx + 1 == entries.Count) {
idx = 0;
} else {
idx++;
}
selected = entries [idx];
}
// returns true if any file was selected
bool SelectNextFileWithMergeConflict ()
{
var idx = entries.IndexOf (selected);
var nextMergeConflict = entries.FindIndex ((idx == -1 || idx >= entries.Count - 1) ? 0 : idx + 1, (v) => v.staged_partially);
if (nextMergeConflict == -1 && idx > -1)
nextMergeConflict = entries.FindIndex ((v) => v.staged_partially);
if (nextMergeConflict == -1)
return false;
selected = entries[nextMergeConflict];
return true;
}
void ShowDiff (bool? staged, bool monoport)
{
string diff = null;
string color;
if (!monoport) {
Console.Clear ();
color = "--color";
} else {
color = "--no-color";
}
if (selected == null) {
if (staged.HasValue && staged.Value) {
if (!monoport) {
Console.ForegroundColor = ConsoleColor.Magenta;
Console.WriteLine ("STAGED DIFF STAGED DIFF STAGED DIFF STAGED DIFF STAGED DIFF STAGED DIFF STAGED DIFF STAGED DIFF STAGED DIFF STAGED DIFF");
Console.ResetColor ();
}
diff = Execute ("git", "diff --staged " + color, monoport);
if (!monoport) {
Console.ForegroundColor = ConsoleColor.Magenta;
Console.WriteLine ("STAGED DIFF STAGED DIFF STAGED DIFF STAGED DIFF STAGED DIFF STAGED DIFF STAGED DIFF STAGED DIFF STAGED DIFF STAGED DIFF");
Console.ResetColor ();
}
} else {
diff = Execute ("git", "diff " + color, monoport);
}
} else {
if (selected.untracked) {
diff = File.ReadAllText (selected.filename);
if (!monoport) {
Console.WriteLine (diff);
}
} else if (((selected.staged_whole || selected.staged) && !(staged.HasValue && !staged.Value)) || (staged.HasValue && staged.Value)) {
if (!monoport) {
Console.ForegroundColor = ConsoleColor.Magenta;
Console.WriteLine ("STAGED DIFF STAGED DIFF STAGED DIFF STAGED DIFF STAGED DIFF STAGED DIFF STAGED DIFF STAGED DIFF STAGED DIFF STAGED DIFF");
Console.ResetColor ();
}
diff = Execute ("git", "diff --staged " + color + " -- " + selected.QuotedFileName, monoport);
if (!monoport) {
Console.ForegroundColor = ConsoleColor.Magenta;
Console.WriteLine ("STAGED DIFF STAGED DIFF STAGED DIFF STAGED DIFF STAGED DIFF STAGED DIFF STAGED DIFF STAGED DIFF STAGED DIFF STAGED DIFF");
Console.ResetColor ();
}
} else {
diff = Execute ("git", "diff " + color + " -- " + selected.QuotedFileName, monoport);
}
}
if (monoport) {
if (string.IsNullOrEmpty (diff)) {
Console.WriteLine ("Diff is empty");
} else {
string tmpfile = Path.GetTempFileName ();
File.WriteAllText (tmpfile, diff);
Execute ("monoport", tmpfile);
File.Delete (tmpfile);
}
}
}
static string FindChangeLog (Entry entry)
{
string find;
string dir = Path.GetDirectoryName (entry.filename);
do {
find = Path.Combine (dir, "ChangeLog");
if (File.Exists (find)) {
Console.WriteLine ("Found ChangeLog in: {0}", dir);
return find;
}
Console.WriteLine ("No ChangeLog in {0} (filename: {1})", dir, entry.filename);
if (dir == "")
break;
dir = Path.GetDirectoryName (dir);
} while (dir != "/");
return null;
}
public void EditChangeLog (Entry selected)
{
if (selected == null)
throw new ArgumentNullException ("You must select a file first");
string changelog = FindChangeLog (selected);
if (changelog == null)
throw new Exception ("No changelog found");
string sdiff = Execute ("git", "diff --staged " + changelog);
string fn = selected.filename.Substring (Path.GetDirectoryName (changelog).Length == 0 ? 0 : Path.GetDirectoryName (changelog).Length + 1);
string content = File.ReadAllText (changelog);
if (string.IsNullOrEmpty (sdiff) || string.IsNullOrEmpty (content)) {
string entry = string.Format (
@"{0:yyyy-MM-dd} Rolf Bjarne Kvinge <RKvinge@novell.com>
* {1}:
", DateTime.Now, fn);
File.WriteAllText (changelog, entry + content);
} else {
string eol = GetEol (changelog);
string l = "\t* " + fn + ":" + eol;
int idx = 0;
idx = content.IndexOf (eol) + eol.Length;
idx = content.IndexOf (eol, idx) + eol.Length;
content = content.Substring (0, idx) + l + content.Substring (idx);
File.WriteAllText (changelog, content);
}
Console.WriteLine ("Opening ChangeLog for editing...");
//Execute ("gnome-terminal", "--maximize -e \"nano -c " + changelog + "\"", false);
Execute ("meld", Path.Combine (Environment.CurrentDirectory, changelog), false);
Execute ("git", "add " + changelog);
Console.WriteLine ("ChangeLog added");
selected.edited_changelog = true;
}
public void FixDate (string filename)
{
string diff = Execute ("git", "diff --staged --no-color -- " + filename, true);
if (string.IsNullOrEmpty (diff)) {
Console.WriteLine ("Nothing diff staged for the file: {0}", filename);
return;
}
string result = System.Text.RegularExpressions.Regex.Replace (diff, @"\+[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9] Rolf Bjarne Kvinge", string.Format ("+{0:yyyy-MM-dd} Rolf Bjarne Kvinge", DateTime.Now));
if (result == diff) {
Console.WriteLine ("Fixing date didn't result in a change (possibly because all dates are correct?) for the file: {0}", filename);
return;
}
//string backup = filename + string.Format (".{0:yyyyMMddHHmmss}.backup", DateTime.Now);
//File.Copy (filename, backup);
Execute ("git", "reset HEAD -- " + filename);
Execute ("git", "co HEAD -- " + filename);
string tmp = Path.GetTempFileName ();
File.WriteAllText (tmp, result);
Execute ("git", "apply " + tmp);
File.Delete (tmp);
Execute ("git", "add " + filename);
Console.WriteLine ("Fixed date in file: {0}", filename);
}
Commands cmds;
void Add (IEnumerable<Entry> values)
{
var not_staged_deleted = values.Where ((v) => !(v.deleted && v.staged));
foreach (var entry_batch in not_staged_deleted.Batch (20)) {
Execute ("git", "add -f -- " + string.Join (" ", entry_batch.Select ((e) => e.QuotedFileName)));
Console.WriteLine ("Added " + string.Join (", ", entry_batch.Select ((e) => e.filename)));
}
}
Entry GetSelectedFile (bool allowUnselected = false)
{
if (selected != null)
return selected;
if (entries.Count == 1)
return entries [0];
if (!allowUnselected)
throw new DiffException ("You need to select a file first.");
return null;
}
void EditSelectedFile ()
{
var selected = GetSelectedFile();
Execute ("gedit", selected.QuotedFileName);
}
bool Do ()
{
string last_cmd = null;
string cmd;
int id;
PrintList ();
cmds = new Commands ()
{
{ "h|help|?", "Show this help message", delegate (string v)
{
cmds.Help ();
}
},
{ "e|edit", "Open file in editor", delegate (string v)
{
EditSelectedFile ();
}
},
{ "gedit", "Open the file in gedit", delegate (string v)
{
var selected = GetSelectedFile ();
Execute ("gedit", selected.QuotedFileName, false, false, false);
}
},
{ "geditall", "Open the files in gedit", delegate (string v)
{
Execute ("gedit", string.Join (" ", entries.Where ((w) => !w.untracked).Select ((w) => w.QuotedFileName).ToArray ()), false, false, false);
}
},
{ "nano", "Open file in nano", delegate (string v)
{
var selected = GetSelectedFile ();
Execute ("nano", "-c " + selected.QuotedFileName, false);
}
},
{ "c|changelog", "Edit ChangeLog for the selected file", delegate (string v)
{
var selected = GetSelectedFile ();
EditChangeLog (selected);
list_dirty = true;
PrintList ();
}
},
{ "a|add", "Add file to index", delegate (string v)
{
var selected = GetSelectedFile ();
list_dirty = true;
if (!(selected.deleted && selected.staged))
Execute ("git", (selected.deleted ? "rm -- " : "add -f -- ") + selected.QuotedFileName);
PrintList ();
}
},
{ "add+next|an", "Add file to index and go to next file", delegate (string v)
{
var selected = GetSelectedFile ();
list_dirty = true;
Execute ("git", (selected.deleted ? "rm -- " : "add -f -- ") + selected.QuotedFileName);
if (selected == null)
throw new DiffException ("You need to select a file first.");
SelectNextFile ();
ShowDiff (null);
}
},
{ "addall|add -u", "Add all changed files to the index", delegate (string v)
{
list_dirty = true;
Add (entries.Where ((e) => !e.untracked));
PrintList ();
}
},
{ "addalluntracked", "Add all untracked files to the index", delegate (string v)
{
list_dirty = true;
Add (entries.Where ((e) => e.untracked));
PrintList ();
}
},
{ "addall+untracked|addall+u", "Add all changed + all untracked files to the index", delegate (string v)
{
list_dirty = true;
Add (entries);
PrintList ();
}
},
{ "ac|addc", "Add file to index and edit changelog", delegate (string v)
{
var selected = GetSelectedFile ();
list_dirty = true;
Execute ("git", (selected.deleted ? "rm -- " : "add -f -- ") + selected.QuotedFileName);
EditChangeLog (selected);
PrintList ();
}
},
{ "and|addanddiff", "Add file to index and immediately show a diff of the staged file", delegate (string v)
{
var selected = GetSelectedFile ();
list_dirty = true;
Execute ("git", (selected.deleted ? "rm -- " : "add -f -- ") + selected.QuotedFileName);
ShowDiff (true);
}
},
{ "p|add -p", "Add file to index in interactive mode", delegate (string v)
{
var selected = GetSelectedFile ();
list_dirty = true;
Execute ("git", "add -p " + selected.QuotedFileName, false);
}
},
{ "ci|gitci|git ci", "Commit using gitci", delegate (string v)
{
Execute ("gitci", "", false);
list_dirty = true;
PrintList ();
}
},
{ "commit", "Commit using git (git commit)", delegate (string v)
{
list_dirty = true;
Execute ("git", "commit", false);
PrintList ();
}
},
{ "fixdate", "Fix the date(s) in the selected ChangeLog", delegate (string v)
{
var selected = GetSelectedFile ();
FixDate (selected.filename);
ShowDiff (null);
}
},
{ "fixdates", "Fix the date(s) in all the ChangeLogs", delegate (string v)
{
foreach (var entry in entries) {
if (entry.filename.EndsWith ("ChangeLog", StringComparison.Ordinal))
FixDate (entry.filename);
}
}
},
{ "d|diff", "Show the diff for the selected file", delegate (string v)
{
ShowDiff (false);
}
},
{ "md|monoport diff", "Monoport the diff of the selected file", delegate (string v)
{
ShowDiff (false, true);
}
},
{ "msd|monoport sdiff", "Monoport the staged diff of the selected file", delegate (string v)
{
ShowDiff (true, true);
}
},
{ "sd|diff --staged|stageddiff|staged diff", "Show the staged diff", delegate (string v)
{
ShowDiff (true);
}
},
{ "rm|delete", "Delete the selected files", delegate (string v)
{
var selected = GetSelectedFile ();
list_dirty = true;
if (selected.untracked) {
Execute ("rm", "-- " + selected.QuotedFileName);
} else {
Execute ("git", "rm -f -- " + selected.QuotedFileName);
}
PrintList ();
}
},
{ "n|next", "Select the next file", delegate (string v)
{
var selected = GetSelectedFile ();
SelectNextFile ();
ShowDiff (null);
}
},
{ "amend", "Executes git commit --amend", delegate (string v)
{
list_dirty = true;
Execute ("git", "commit --amend", false);
PrintList ();
}
},
{ "reset", "Executes git reset on the selected file", delegate (string v)
{
list_dirty = true;
if (selected == null) {
Execute ("git", "reset");
PrintList ();
} else {
Execute ("git", "reset -- " + selected.QuotedFileName);
var selected_file = selected.filename;
RefreshList ();
selected = entries.Single (v => v.filename == selected_file);
ShowDiff (null);
}
}
},
{ "reset-conflicts", "Executes git reset on files with conflicts", delegate (string v)
{
var filesWithMergeConflicts = entries.Where (v => v.staged_partially);
if (filesWithMergeConflicts.Any ()) {
list_dirty = true;
Execute ("git", "reset -- " + string.Join (" ", filesWithMergeConflicts.Select (v => v.QuotedFileName)));
RefreshList ();
PrintList ();
}
}
},
{ "checkout", "Checks out the selected file (equivalent to svn revert)", delegate (string v)
{
var selected = GetSelectedFile ();
list_dirty = true;
Execute ("git", "checkout " + selected.QuotedFileName);
PrintList ();
}
},
{ "checkout+next|chn", "Checks out the selected file and advances to the next file", delegate (string v)
{
var selected = GetSelectedFile ();
list_dirty = true;
Execute ("git", "checkout " + selected.QuotedFileName);
SelectNextFile ();
ShowDiff (null);
}
},
{ "meld", "View the selected file in meld", delegate (string v)
{
var selected = GetSelectedFile ();
list_dirty = true;
Execute ("muld", Path.Combine (Environment.CurrentDirectory, selected.QuotedFileName), false);
}
},
{ "gui", "Run git gui", delegate (string v)
{
Execute ("git", "gui", false, false);
}
},
{ "r|refresh", "Refresh the list", delegate (string v)
{
list_dirty = true;
PrintList ();
}
},
{ "l|list", "Show the list again", delegate (string v)
{
PrintList ();
}
},
{ "q|quit|QUIT", "Quit", delegate (string v)
{
Environment.Exit (0);
}
},
{ "fixeol", "Fix eol-style for the all the files which have eol-style problems", delegate (string v)
{
for (int i = 0; i < entries.Count; i++) {
if (!entries [i].messed_up_eol)
continue;
Fixeol (entries [i]);
}
list_dirty = true;
PrintList ();
}
},
{ "dos2unix|dosunix", "Change the eol-style to unix for the selected file", delegate (string v)
{
var selected = GetSelectedFile ();
Dos2Unix (selected.filename);
if (selected.staged_whole)
Execute ("git", "add -f " + selected.QuotedFileName);
list_dirty = true;
ShowDiff (null);
}
},
{ "unix2dos|unixdos", "Change the eol-style to dos for the selected file", delegate (string v)
{
var selected = GetSelectedFile ();
Unix2Dos (selected.filename);
ShowDiff (null);
}
},
{ "i|ignore", "Add file to .gitignore in current directory", delegate (string v)
{
var selected = GetSelectedFile ();
File.AppendAllText (Path.Combine (Path.GetDirectoryName (selected.filename), ".gitignore"), Path.GetFileName (selected.filename) + '\n');
list_dirty = true;
}
},
{ "ignore-extension", "Add extension of file to .gitignore in current directory", delegate (string v)
{
var selected = GetSelectedFile ();
File.AppendAllText (Path.Combine (Path.GetDirectoryName (selected.filename), ".gitignore"), "*" + Path.GetExtension (selected.filename) + '\n');
list_dirty = true;
}
},
{ "log", "Run 'git log' on the selected file", (v) =>
{
var selected = GetSelectedFile ();
Execute ("git", "log -- " + selected.QuotedFileName, false, true);
}
},
{ "log --oneline", "Run 'git log --oneline' on the selected file", (v) =>
{
var selected = GetSelectedFile ();
Execute ("git", "log --oneline -- " + selected.QuotedFileName, false, true);
}
},
{ "blame", "Run 'git blame' on the selected file", (v) =>
{
var selected = GetSelectedFile ();
Execute ("git", "blame -- " + selected.QuotedFileName, false, true);
}
},
{ "commit *", "Commit using the specified commit message", (v) =>
{
var msg = v.Substring ("commit ".Length).Trim ();
if (msg.Length == 0)
throw new DiffException ("Commit message is empty");
if (selected != null)
Execute ("git", "add -f -- " + selected.QuotedFileName, false, true);
Execute ("git", $"commit -m \"{msg}\"", false, true);
list_dirty = true;
PrintList ();
}
},
{ "z", "Amend HEAD with the current staged changes", (v) =>
{
if (selected != null)
Execute ("git", "add -f -- " + selected.QuotedFileName, false, true);
Execute ("git", $"commit --amend -C HEAD", false, true);
list_dirty = true;
PrintList ();
}
},
{ "ame", "Add selected (if any), edit next file with a merge conflict", (v) =>
{
var selected = GetSelectedFile (allowUnselected: true);
if (selected is not null) {
Execute ("git", (selected.deleted ? "rm -- " : "add ") + selected.QuotedFileName);
RefreshList ();
}
list_dirty = true;
if (SelectNextFileWithMergeConflict ()) {
EditSelectedFile ();
} else {
PrintList ();
}
}
},
};
do {
PrintCommands ();
cmd = Console.ReadLine ();
if (string.IsNullOrEmpty (cmd))
cmd = last_cmd;
last_cmd = cmd;
if (int.TryParse (cmd, out id) && id >= 1 && id <= entries.Count) {
selected = entries [id - 1];
if (selected != null && selected.untracked) {
// don't show anything, the common case is to select a file to delete it, in which case showing the entire file can be annoying
Console.WriteLine ("Selected untracked file {0}", selected.filename);
} else {
ShowDiff (null);
}
continue;
}
bool executed = cmds.Execute (cmd);
if (executed)
continue;
Console.WriteLine ("Unrecognized command: '{0}'", cmd);
} while (true);
}
void PrintCommands ()
{
if (selected != null)
Console.WriteLine ("{0} {1}", entries.IndexOf (selected) + 1, selected.filename);
Console.Write ("Now what? ");
}
void PrintList ()
{
Console.Clear ();
if (list_dirty)
RefreshList ();
bool any_eol_issues = false;
bool any_staged = false;
bool any_staged_partially = false;
bool any_deleted = false;
bool any_untracked = false;
bool any_binaries = false;
int max_filename_length = 0;
ConsoleColor color = ConsoleColor.Black;
for (int i = 0; i < entries.Count; i++) {
any_eol_issues |= entries [i].messed_up_eol;
any_staged_partially |= entries [i].staged_partially;
any_staged |= entries [i].staged_whole;
any_deleted |= entries [i].deleted;
any_untracked |= entries [i].untracked;
any_binaries |= entries [i].is_binary;
max_filename_length = Math.Max (max_filename_length, entries [i].filename.Length);
}
// Console.Clear ();
for (int i = 0; i < entries.Count; i++) {
color = ConsoleColor.Black;
if (selected != null && selected == entries [i]) {
Console.Write ("*");
} else {
Console.Write (" ");
}
if (any_staged || any_staged_partially) {
if (entries [i].staged_whole) {
Console.Write ("staged ");
if (any_staged_partially)
Console.Write (" ");
color = ConsoleColor.Blue;
} else if (entries [i].staged) {
Console.Write ("staged (partially) ");
color = ConsoleColor.DarkBlue;
} else {
if (any_staged_partially) {
Console.Write (" - ");
} else {
Console.Write (" - ");
}
}
}
if (any_binaries) {
if (entries [i].is_binary) {
Console.Write ("binary ");
color = ConsoleColor.DarkGreen;
} else {
Console.Write (" ");
}
}
if (any_deleted) {
if (entries [i].deleted) {
Console.Write ("deleted ");
color = ConsoleColor.Red;
} else {
Console.Write (" - ");
}
}
if (any_untracked) {
if (entries [i].untracked) {
Console.Write ("untracked ");
color = ConsoleColor.Yellow;
} else {
Console.Write (" - ");
}
}
Console.Write (" ");
if (any_eol_issues) {
if (entries [i].messed_up_eol) {
Console.Write ("EOL ");
color = ConsoleColor.Magenta;
} else {
Console.Write (" ");
}
}
if (entries.Count <= 9) {
Console.Write ("{0,-1} ", i + 1);
} else if (entries.Count <= 99) {
Console.Write ("{0,-2} ", i + 1);
} else {
Console.Write ("{0,-3} ", i + 1);
}
Console.Write (" ");
Console.Write (entries [i].eol);
Console.Write (" ");
if (color != ConsoleColor.Black)
Console.ForegroundColor = color;
Console.Write (entries [i].filename.Substring (PREFIX.Length));
Console.ResetColor ();
if (entries [i].is_directory)
Console.WriteLine (" [DIRECTORY]");
Console.WriteLine ();
}
}
}
}