44//
55
66using System ;
7+ using System . Collections . Generic ;
78
89namespace ColorTool
910{
11+ /// <summary>
12+ /// Displays the color table that demonstrates the current colorscheme.
13+ /// </summary>
1014 class ColorTable
1115 {
12- static int DARK_BLACK = 0 ;
13- static int DARK_BLUE = 1 ;
14- static int DARK_GREEN = 2 ;
15- static int DARK_CYAN = 3 ;
16- static int DARK_RED = 4 ;
17- static int DARK_MAGENTA = 5 ;
18- static int DARK_YELLOW = 6 ;
19- static int DARK_WHITE = 7 ;
20- static int BRIGHT_BLACK = 8 ;
21- static int BRIGHT_BLUE = 9 ;
22- static int BRIGHT_GREEN = 10 ;
23- static int BRIGHT_CYAN = 11 ;
24- static int BRIGHT_RED = 12 ;
25- static int BRIGHT_MAGENTA = 13 ;
26- static int BRIGHT_YELLOW = 14 ;
27- static int BRIGHT_WHITE = 15 ;
16+ const int DARK_BLACK = 0 ;
17+ const int DARK_BLUE = 1 ;
18+ const int DARK_GREEN = 2 ;
19+ const int DARK_CYAN = 3 ;
20+ const int DARK_RED = 4 ;
21+ const int DARK_MAGENTA = 5 ;
22+ const int DARK_YELLOW = 6 ;
23+ const int DARK_WHITE = 7 ;
24+ const int BRIGHT_BLACK = 8 ;
25+ const int BRIGHT_BLUE = 9 ;
26+ const int BRIGHT_GREEN = 10 ;
27+ const int BRIGHT_CYAN = 11 ;
28+ const int BRIGHT_RED = 12 ;
29+ const int BRIGHT_MAGENTA = 13 ;
30+ const int BRIGHT_YELLOW = 14 ;
31+ const int BRIGHT_WHITE = 15 ;
2832
2933 // This is the order of colors when output by the table.
30- static int [ ] outputFgs = {
31- BRIGHT_WHITE ,
32- DARK_BLACK ,
33- BRIGHT_BLACK ,
34- DARK_RED ,
35- BRIGHT_RED ,
36- DARK_GREEN ,
37- BRIGHT_GREEN ,
38- DARK_YELLOW ,
39- BRIGHT_YELLOW ,
40- DARK_BLUE ,
41- BRIGHT_BLUE ,
42- DARK_MAGENTA ,
43- BRIGHT_MAGENTA ,
44- DARK_CYAN ,
45- BRIGHT_CYAN ,
46- DARK_WHITE ,
34+ private static readonly IReadOnlyList < int > outputFgs = new [ ]
35+ {
36+ BRIGHT_WHITE ,
37+ DARK_BLACK ,
38+ BRIGHT_BLACK ,
39+ DARK_RED ,
40+ BRIGHT_RED ,
41+ DARK_GREEN ,
42+ BRIGHT_GREEN ,
43+ DARK_YELLOW ,
44+ BRIGHT_YELLOW ,
45+ DARK_BLUE ,
46+ BRIGHT_BLUE ,
47+ DARK_MAGENTA ,
48+ BRIGHT_MAGENTA ,
49+ DARK_CYAN ,
50+ BRIGHT_CYAN ,
51+ DARK_WHITE ,
4752 BRIGHT_WHITE
4853 } ;
4954
55+ private const string TestText = " gYw " ;
5056
51- static int [ ] saneBgs = {
52- DARK_BLACK ,
53- DARK_RED ,
54- DARK_GREEN ,
55- DARK_YELLOW ,
56- DARK_BLUE ,
57- DARK_MAGENTA ,
58- DARK_CYAN ,
59- DARK_WHITE
57+ private static readonly IReadOnlyList < string > FGs = new [ ]
58+ {
59+ "m" ,
60+ "1m" ,
61+ "30m" ,
62+ "1;30m" ,
63+ "31m" ,
64+ "1;31m" ,
65+ "32m" ,
66+ "1;32m" ,
67+ "33m" ,
68+ "1;33m" ,
69+ "34m" ,
70+ "1;34m" ,
71+ "35m" ,
72+ "1;35m" ,
73+ "36m" ,
74+ "1;36m" ,
75+ "37m" ,
76+ "1;37m"
6077 } ;
6178
79+ private static readonly IReadOnlyList < string > BGs = new [ ]
80+ {
81+ "m" ,
82+ "40m" ,
83+ "41m" ,
84+ "42m" ,
85+ "43m" ,
86+ "44m" ,
87+ "45m" ,
88+ "46m" ,
89+ "47m"
90+ } ;
91+
92+ private static readonly IReadOnlyList < int > saneBgs = new [ ]
93+ {
94+ DARK_BLACK ,
95+ DARK_RED ,
96+ DARK_GREEN ,
97+ DARK_YELLOW ,
98+ DARK_BLUE ,
99+ DARK_MAGENTA ,
100+ DARK_CYAN ,
101+ DARK_WHITE
102+ } ;
62103
63104 public static void PrintTable ( )
64105 {
65106 ConsoleColor [ ] colors = ( ConsoleColor [ ] ) ConsoleColor . GetValues ( typeof ( ConsoleColor ) ) ;
66107 // Save the current background and foreground colors.
67108 ConsoleColor currentBackground = Console . BackgroundColor ;
68109 ConsoleColor currentForeground = Console . ForegroundColor ;
69- string test = " gYw " ;
70- string [ ] FGs = {
71- "m" ,
72- "1m" ,
73- "30m" ,
74- "1;30m" ,
75- "31m" ,
76- "1;31m" ,
77- "32m" ,
78- "1;32m" ,
79- "33m" ,
80- "1;33m" ,
81- "34m" ,
82- "1;34m" ,
83- "35m" ,
84- "1;35m" ,
85- "36m" ,
86- "1;36m" ,
87- "37m" ,
88- "1;37m"
89- } ;
90- string [ ] BGs = {
91- "m" ,
92- "40m" ,
93- "41m" ,
94- "42m" ,
95- "43m" ,
96- "44m" ,
97- "45m" ,
98- "46m" ,
99- "47m"
100- } ;
101110
102111 Console . Write ( "\t " ) ;
103- for ( int bg = 0 ; bg < BGs . Length ; bg ++ )
112+ for ( int bg = 0 ; bg < BGs . Count ; bg ++ )
104113 {
105114 if ( bg > 0 ) Console . Write ( " " ) ;
106115 Console . Write ( " " ) ;
@@ -109,7 +118,7 @@ public static void PrintTable()
109118 }
110119 Console . WriteLine ( ) ;
111120
112- for ( int fg = 0 ; fg < FGs . Length ; fg ++ )
121+ for ( int fg = 0 ; fg < FGs . Count ; fg ++ )
113122 {
114123 Console . ForegroundColor = currentForeground ;
115124 Console . BackgroundColor = currentBackground ;
@@ -119,13 +128,13 @@ public static void PrintTable()
119128 if ( fg == 0 ) Console . ForegroundColor = currentForeground ;
120129 else Console . ForegroundColor = colors [ outputFgs [ fg - 1 ] ] ;
121130
122- for ( int bg = 0 ; bg < BGs . Length ; bg ++ )
131+ for ( int bg = 0 ; bg < BGs . Count ; bg ++ )
123132 {
124133 if ( bg > 0 ) Console . Write ( " " ) ;
125134 if ( bg == 0 )
126135 Console . BackgroundColor = currentBackground ;
127136 else Console . BackgroundColor = colors [ saneBgs [ bg - 1 ] ] ;
128- Console . Write ( test ) ;
137+ Console . Write ( TestText ) ;
129138 Console . BackgroundColor = currentBackground ;
130139 }
131140 Console . Write ( "\n " ) ;
@@ -140,42 +149,8 @@ public static void PrintTable()
140149
141150 public static void PrintTableWithVt ( )
142151 {
143- // Save the current background and foreground colors.
144- string test = " gYw " ;
145- string [ ] FGs = {
146- "m" ,
147- "1m" ,
148- "30m" ,
149- "1;30m" ,
150- "31m" ,
151- "1;31m" ,
152- "32m" ,
153- "1;32m" ,
154- "33m" ,
155- "1;33m" ,
156- "34m" ,
157- "1;34m" ,
158- "35m" ,
159- "1;35m" ,
160- "36m" ,
161- "1;36m" ,
162- "37m" ,
163- "1;37m"
164- } ;
165- string [ ] BGs = {
166- "m" ,
167- "40m" ,
168- "41m" ,
169- "42m" ,
170- "43m" ,
171- "44m" ,
172- "45m" ,
173- "46m" ,
174- "47m"
175- } ;
176-
177152 Console . Write ( "\t " ) ;
178- for ( int bg = 0 ; bg < BGs . Length ; bg ++ )
153+ for ( int bg = 0 ; bg < BGs . Count ; bg ++ )
179154 {
180155 if ( bg > 0 ) Console . Write ( " " ) ;
181156 Console . Write ( " " ) ;
@@ -184,7 +159,7 @@ public static void PrintTableWithVt()
184159 }
185160 Console . WriteLine ( ) ;
186161
187- for ( int fg = 0 ; fg < FGs . Length ; fg ++ )
162+ for ( int fg = 0 ; fg < FGs . Count ; fg ++ )
188163 {
189164 Console . Write ( "\x1b [m" ) ;
190165
@@ -202,7 +177,7 @@ public static void PrintTableWithVt()
202177 Console . Write ( "\x1b [" + FGs [ fg ] ) ;
203178 }
204179
205- for ( int bg = 0 ; bg < BGs . Length ; bg ++ )
180+ for ( int bg = 0 ; bg < BGs . Count ; bg ++ )
206181 {
207182 if ( bg > 0 )
208183 {
@@ -217,7 +192,7 @@ public static void PrintTableWithVt()
217192 Console . Write ( "\x1b [" + BGs [ bg ] ) ;
218193 }
219194
220- Console . Write ( test ) ;
195+ Console . Write ( TestText ) ;
221196 Console . Write ( "\x1b [49m" ) ;
222197 }
223198 Console . Write ( "\n " ) ;
0 commit comments