@@ -36,9 +36,7 @@ class ColorParser implements IReader<StringTokenValue> {
36
36
ColorToken ? _getToken () {
37
37
var token = ColorToken .empty ();
38
38
final char = reader.peek ();
39
- // print('');
40
39
// print('char: ${_debugString(char ?? '<null>')}');
41
- // print('');
42
40
43
41
switch (char) {
44
42
case null :
@@ -97,6 +95,9 @@ class ColorParser implements IReader<StringTokenValue> {
97
95
if (_checkBetween (color, 100 , 107 )) {
98
96
token.brightBg = true ;
99
97
}
98
+ } else {
99
+ // Catch arbitrary/unhandled codes
100
+ token.setStyle (color);
100
101
}
101
102
colors.removeAt (0 );
102
103
}
@@ -113,6 +114,9 @@ class ColorParser implements IReader<StringTokenValue> {
113
114
}
114
115
115
116
ColorToken _consumeRgbToken (ColorToken token, List <String > colors) {
117
+ if (colors.length < 5 ) {
118
+ return token;
119
+ }
116
120
final rgb = '${colors [2 ]};${colors [3 ]};${colors [4 ]}' ;
117
121
if (colors[0 ] == '38' ) {
118
122
token.rgbFg = true ;
@@ -125,6 +129,9 @@ class ColorParser implements IReader<StringTokenValue> {
125
129
}
126
130
127
131
ColorToken _consumeXterm256Token (ColorToken token, List <String > colors) {
132
+ if (colors.length < 3 ) {
133
+ return token;
134
+ }
128
135
final color = int .parse (colors[2 ]);
129
136
if (colors[0 ] == '38' ) {
130
137
token.xterm256 = true ;
@@ -144,51 +151,6 @@ class ColorParser implements IReader<StringTokenValue> {
144
151
return min <= value && value <= max;
145
152
}
146
153
147
- // ColorToken _consumeStyleToken(ColorToken token) {
148
- // // print('Consuming style token for $token');
149
- // final color = _consumeUntil('m');
150
- // reader.read();
151
- //
152
- // if (!color.contains(';')) {
153
- // //single number color [30-37] / [40-47]
154
- // // or [90-97] / [100-107], fg / bg
155
- // // e.g. ^[40m
156
- // // or just style ? e.g. ^[1m
157
- //
158
- // // TODO: this seems to crash on ^[40m, don't understand exactly why
159
- // // doesn't seem to be the 40m, that one gets interpreted well (black bg)
160
- //
161
- // int colorValue = -1;
162
- // try {
163
- // colorValue = int.parse(color);
164
- // } on FormatException {
165
- // // ignore, then??
166
- // // print("failing color= " + color);
167
- // // TODO: it keeps logging thousands of empty "failing colors" ?
168
- // }
169
- // if (colorValue > -1) { // init safely, ignore if nothing ?
170
- // if ((30 <= colorValue) && (colorValue <= 37) ||
171
- // (90 <= colorValue) && (colorValue <= 97)) {
172
- // token.fgColor = colorValue;
173
- // } else if ((40 <= colorValue) && (colorValue <= 47) ||
174
- // (100 <= colorValue) && (colorValue <= 107)) {
175
- // token.bgColor = colorValue;
176
- // } else if (colorValue < 30) { // style ?
177
- // token.setStyle(colorValue);
178
- // }
179
- // }
180
- // }
181
- // // things like ^[1;38;2;114;150;50;48;2;125;70;22m TEXT ^[0m
182
- // else { // multi number madness, trying recursive parser ?
183
- // final colors = color.split(';');
184
- // processTokenStyle(colors, token); //really hope this works by reference
185
- // }
186
- // if (reader.peek() == Consts.esc) {
187
- // return _consumeEscSequence(token);
188
- // }
189
- // return token;
190
- // }
191
-
192
154
ColorToken _consumeText (ColorToken token) {
193
155
// print('Consuming text for $token');
194
156
token.text += _consumeUntil (Consts .esc);
@@ -238,70 +200,6 @@ class ColorParser implements IReader<StringTokenValue> {
238
200
return result;
239
201
}
240
202
241
- // processTokenStyle(List<String> colors, ColorToken token) {
242
- // if (colors.isNotEmpty) {
243
- // //if it's already empty, do nothing more
244
- // int first = int.parse(colors[0]);
245
- // if (first < 30) {
246
- // // bold, underline, etc?
247
- // token.setStyle(first);
248
- // colors.removeAt(0);
249
- // } else if ((30 <= first) && (first <= 37) ||
250
- // (90 <= first) && (first <= 97) ||
251
- // (40 <= first) && (first <= 47) ||
252
- // (100 <= first) && (first <= 107)) {
253
- // if ((30 <= first) && (first <= 37) || (90 <= first) && (first <= 97)) {
254
- // token.fgColor = first;
255
- // colors.removeAt(0);
256
- // } else if ((40 <= first) && (first <= 47) ||
257
- // (100 <= first) && (first <= 107)) {
258
- // token.bgColor = first;
259
- // colors.removeAt(0);
260
- // }
261
- // } else {
262
- // int second = int.parse(colors[1]);
263
- // if (first == 38 && second == 5) {
264
- // token.xterm256 = true;
265
- // int third = int.parse(colors[2]);
266
- // token.fgColor = third;
267
- // colors.removeRange(0, 3);
268
- // // bg = 0;
269
- // } else if (first == 48 && second == 5) {
270
- // token.xterm256 = true;
271
- // int third = int.parse(colors[2]);
272
- // token.bgColor = third;
273
- // colors.removeRange(0, 3);
274
- // // bg = 0;
275
- // } else {
276
- // if (first == 38 && second == 2) {
277
- // //rgb
278
- // String red = colors[2];
279
- // String green = colors[3];
280
- // String blue = colors[4];
281
- // token.rgbFg = true;
282
- // token.rgbFgColor = "$red;$green;$blue";
283
- // colors.removeRange(0, 5);
284
- // } else if (first == 48 && second == 2) {
285
- // //rgb
286
- // String red = colors[2];
287
- // String green = colors[3];
288
- // String blue = colors[4];
289
- // token.rgbBg = true;
290
- // token.rgbBgColor = "$red;$green;$blue";
291
- // colors.removeRange(0, 5);
292
- // } else {
293
- // return;
294
- // }
295
- // }
296
- // }
297
- // //pass the rest of the color codes, hope for the best
298
- // if (colors.isNotEmpty) {
299
- // processTokenStyle(
300
- // colors, token); // really really hoping these go by reference
301
- // }
302
- // }
303
- // }
304
-
305
203
// ignore: unused_element
306
204
_debugString (String string) => string.replaceAll ('\x 1B' , '\\ x1B' );
307
205
0 commit comments