on master help sign in
Fix base16, and combine 00 and 0f alpha encodings

This changes the base16 theme back from #RRGGBB0f to #RRGGBB00, reverting part of #934. That PR used the 0f encoding to produce ANSI escape sequences 30-37 and 40-47 rather than 38;5 and 48;5 which require 256-color support. Unfortunately, it resulted in base16 using the wrong colors becuase ansi_term does not support the bright variants (90-97 and 100-107) so it simply mapped them to the non-bright colors. This PR makes combines the 00 and 0f alpha encodings into 00, and makes them use the Color enum for the first 8 colors and Fixed otherwise. This means the ansi-light and ansi-dark themes will work on terminals without 256-color support, and base16 will render bright colors correctly.

commitf59d00d4c722de05af561666d58d15600c749c1d authorMitchell Kember <mk12360@gmail.com> dateSat 2 May 2020, 14:28 (7 years ago) parentdcfdbf8
2 files changed+73−73
assets/themes/base16.tmTheme+59−59 src/terminal.rs+14−14
assets/themes/base16.tmTheme+59−59
@@ -3,8 +3,8 @@
33<plist version="1.0">
44 <dict>
55 <!--
6− The colors in this theme are encoded as #RRGGBBAA where RR is an base16
7− color number from 00 to 0f, and AA is the special value 0f to indicate
6+ The colors in this theme are encoded as #RRGGBBAA where RR is an ANSI
7+ palette number from 00 to 0f, and AA is the special value 00 to indicate
88 that this encoding is being used.
99 -->
1010 <key>author</key>
@@ -19,21 +19,21 @@
1919 <key>settings</key>
2020 <dict>
2121 <key>background</key>
22− <string>#0000000f</string>
22+ <string>#00000000</string>
2323 <key>caret</key>
24− <string>#0700000f</string>
24+ <string>#07000000</string>
2525 <key>foreground</key>
26− <string>#0700000f</string>
26+ <string>#07000000</string>
2727 <key>invisibles</key>
28− <string>#0800000f</string>
28+ <string>#08000000</string>
2929 <key>lineHighlight</key>
30− <string>#0800000f</string>
30+ <string>#08000000</string>
3131 <key>selection</key>
32− <string>#0b00000f</string>
32+ <string>#0b000000</string>
3333 <key>gutter</key>
34− <string>#0a00000f</string>
34+ <string>#0a000000</string>
3535 <key>gutterForeground</key>
36− <string>#0800000f</string>
36+ <string>#08000000</string>
3737 </dict>
3838 </dict>
3939 <dict>
@@ -44,7 +44,7 @@
4444 <key>settings</key>
4545 <dict>
4646 <key>foreground</key>
47− <string>#0700000f</string>
47+ <string>#07000000</string>
4848 </dict>
4949 </dict>
5050 <dict>
@@ -55,7 +55,7 @@
5555 <key>settings</key>
5656 <dict>
5757 <key>foreground</key>
58− <string>#0800000f</string>
58+ <string>#08000000</string>
5959 </dict>
6060 </dict>
6161 <dict>
@@ -66,7 +66,7 @@
6666 <key>settings</key>
6767 <dict>
6868 <key>foreground</key>
69− <string>#0700000f</string>
69+ <string>#07000000</string>
7070 </dict>
7171 </dict>
7272 <dict>
@@ -77,7 +77,7 @@
7777 <key>settings</key>
7878 <dict>
7979 <key>foreground</key>
80− <string>#0700000f</string>
80+ <string>#07000000</string>
8181 </dict>
8282 </dict>
8383 <dict>
@@ -88,7 +88,7 @@
8888 <key>settings</key>
8989 <dict>
9090 <key>foreground</key>
91− <string>#0700000f</string>
91+ <string>#07000000</string>
9292 </dict>
9393 </dict>
9494 <dict>
@@ -99,7 +99,7 @@
9999 <key>settings</key>
100100 <dict>
101101 <key>foreground</key>
102− <string>#0500000f</string>
102+ <string>#05000000</string>
103103 </dict>
104104 </dict>
105105 <dict>
@@ -110,7 +110,7 @@
110110 <key>settings</key>
111111 <dict>
112112 <key>foreground</key>
113− <string>#0700000f</string>
113+ <string>#07000000</string>
114114 </dict>
115115 </dict>
116116 <dict>
@@ -121,7 +121,7 @@
121121 <key>settings</key>
122122 <dict>
123123 <key>foreground</key>
124− <string>#0400000f</string>
124+ <string>#04000000</string>
125125 </dict>
126126 </dict>
127127 <dict>
@@ -132,7 +132,7 @@
132132 <key>settings</key>
133133 <dict>
134134 <key>foreground</key>
135− <string>#0e00000f</string>
135+ <string>#0e000000</string>
136136 </dict>
137137 </dict>
138138 <dict>
@@ -143,7 +143,7 @@
143143 <key>settings</key>
144144 <dict>
145145 <key>foreground</key>
146− <string>#0300000f</string>
146+ <string>#03000000</string>
147147 </dict>
148148 </dict>
149149 <dict>
@@ -154,7 +154,7 @@
154154 <key>settings</key>
155155 <dict>
156156 <key>foreground</key>
157− <string>#0f00000f</string>
157+ <string>#0f000000</string>
158158 </dict>
159159 </dict>
160160 <dict>
@@ -165,7 +165,7 @@
165165 <key>settings</key>
166166 <dict>
167167 <key>foreground</key>
168− <string>#0400000f</string>
168+ <string>#04000000</string>
169169 </dict>
170170 </dict>
171171 <dict>
@@ -176,7 +176,7 @@
176176 <key>settings</key>
177177 <dict>
178178 <key>foreground</key>
179− <string>#0500000f</string>
179+ <string>#05000000</string>
180180 </dict>
181181 </dict>
182182 <dict>
@@ -187,7 +187,7 @@
187187 <key>settings</key>
188188 <dict>
189189 <key>foreground</key>
190− <string>#0600000f</string>
190+ <string>#06000000</string>
191191 </dict>
192192 </dict>
193193 <dict>
@@ -198,7 +198,7 @@
198198 <key>settings</key>
199199 <dict>
200200 <key>foreground</key>
201− <string>#0200000f</string>
201+ <string>#02000000</string>
202202 </dict>
203203 </dict>
204204 <dict>
@@ -209,7 +209,7 @@
209209 <key>settings</key>
210210 <dict>
211211 <key>foreground</key>
212− <string>#0900000f</string>
212+ <string>#09000000</string>
213213 </dict>
214214 </dict>
215215 <dict>
@@ -220,7 +220,7 @@
220220 <key>settings</key>
221221 <dict>
222222 <key>foreground</key>
223− <string>#0900000f</string>
223+ <string>#09000000</string>
224224 </dict>
225225 </dict>
226226 <dict>
@@ -231,7 +231,7 @@
231231 <key>settings</key>
232232 <dict>
233233 <key>foreground</key>
234− <string>#0900000f</string>
234+ <string>#09000000</string>
235235 </dict>
236236 </dict>
237237 <dict>
@@ -242,7 +242,7 @@
242242 <key>settings</key>
243243 <dict>
244244 <key>foreground</key>
245− <string>#0900000f</string>
245+ <string>#09000000</string>
246246 </dict>
247247 </dict>
248248 <dict>
@@ -253,7 +253,7 @@
253253 <key>settings</key>
254254 <dict>
255255 <key>foreground</key>
256− <string>#0100000f</string>
256+ <string>#01000000</string>
257257 </dict>
258258 </dict>
259259 <dict>
@@ -264,7 +264,7 @@
264264 <key>settings</key>
265265 <dict>
266266 <key>foreground</key>
267− <string>#0900000f</string>
267+ <string>#09000000</string>
268268 </dict>
269269 </dict>
270270 <dict>
@@ -275,7 +275,7 @@
275275 <key>settings</key>
276276 <dict>
277277 <key>foreground</key>
278− <string>#0400000f</string>
278+ <string>#04000000</string>
279279 </dict>
280280 </dict>
281281 <dict>
@@ -286,7 +286,7 @@
286286 <key>settings</key>
287287 <dict>
288288 <key>foreground</key>
289− <string>#0500000f</string>
289+ <string>#05000000</string>
290290 </dict>
291291 </dict>
292292 <dict>
@@ -297,7 +297,7 @@
297297 <key>settings</key>
298298 <dict>
299299 <key>foreground</key>
300− <string>#0900000f</string>
300+ <string>#09000000</string>
301301 </dict>
302302 </dict>
303303 <dict>
@@ -310,7 +310,7 @@
310310 <key>fontStyle</key>
311311 <string></string>
312312 <key>foreground</key>
313− <string>#0400000f</string>
313+ <string>#04000000</string>
314314 </dict>
315315 </dict>
316316 <dict>
@@ -321,7 +321,7 @@
321321 <key>settings</key>
322322 <dict>
323323 <key>foreground</key>
324− <string>#0900000f</string>
324+ <string>#09000000</string>
325325 </dict>
326326 </dict>
327327 <dict>
@@ -334,7 +334,7 @@
334334 <key>fontStyle</key>
335335 <string>bold</string>
336336 <key>foreground</key>
337− <string>#0300000f</string>
337+ <string>#03000000</string>
338338 </dict>
339339 </dict>
340340 <dict>
@@ -347,7 +347,7 @@
347347 <key>fontStyle</key>
348348 <string>italic</string>
349349 <key>foreground</key>
350− <string>#0500000f</string>
350+ <string>#05000000</string>
351351 </dict>
352352 </dict>
353353 <dict>
@@ -358,7 +358,7 @@
358358 <key>settings</key>
359359 <dict>
360360 <key>foreground</key>
361− <string>#0200000f</string>
361+ <string>#02000000</string>
362362 </dict>
363363 </dict>
364364 <dict>
@@ -369,7 +369,7 @@
369369 <key>settings</key>
370370 <dict>
371371 <key>foreground</key>
372− <string>#0100000f</string>
372+ <string>#01000000</string>
373373 </dict>
374374 </dict>
375375 <dict>
@@ -380,7 +380,7 @@
380380 <key>settings</key>
381381 <dict>
382382 <key>foreground</key>
383− <string>#0900000f</string>
383+ <string>#09000000</string>
384384 </dict>
385385 </dict>
386386 <dict>
@@ -391,7 +391,7 @@
391391 <key>settings</key>
392392 <dict>
393393 <key>foreground</key>
394− <string>#0900000f</string>
394+ <string>#09000000</string>
395395 </dict>
396396 </dict>
397397 <dict>
@@ -402,9 +402,9 @@
402402 <key>settings</key>
403403 <dict>
404404 <key>background</key>
405− <string>#0b00000f</string>
405+ <string>#0b000000</string>
406406 <key>foreground</key>
407− <string>#0700000f</string>
407+ <string>#07000000</string>
408408 </dict>
409409 </dict>
410410 <dict>
@@ -415,7 +415,7 @@
415415 <key>settings</key>
416416 <dict>
417417 <key>foreground</key>
418− <string>#0200000f</string>
418+ <string>#02000000</string>
419419 </dict>
420420 </dict>
421421 <dict>
@@ -426,7 +426,7 @@
426426 <key>settings</key>
427427 <dict>
428428 <key>foreground</key>
429− <string>#0100000f</string>
429+ <string>#01000000</string>
430430 </dict>
431431 </dict>
432432 <dict>
@@ -437,7 +437,7 @@
437437 <key>settings</key>
438438 <dict>
439439 <key>foreground</key>
440− <string>#0500000f</string>
440+ <string>#05000000</string>
441441 </dict>
442442 </dict>
443443 <dict>
@@ -448,7 +448,7 @@
448448 <key>settings</key>
449449 <dict>
450450 <key>foreground</key>
451− <string>#0600000f</string>
451+ <string>#06000000</string>
452452 </dict>
453453 </dict>
454454 <dict>
@@ -459,7 +459,7 @@
459459 <key>settings</key>
460460 <dict>
461461 <key>foreground</key>
462− <string>#0600000f</string>
462+ <string>#06000000</string>
463463 </dict>
464464 </dict>
465465 <dict>
@@ -470,7 +470,7 @@
470470 <key>settings</key>
471471 <dict>
472472 <key>foreground</key>
473− <string>#0600000f</string>
473+ <string>#06000000</string>
474474 </dict>
475475 </dict>
476476 <dict>
@@ -481,7 +481,7 @@
481481 <key>settings</key>
482482 <dict>
483483 <key>foreground</key>
484− <string>#0500000f</string>
484+ <string>#05000000</string>
485485 </dict>
486486 </dict>
487487 <dict>
@@ -492,9 +492,9 @@
492492 <key>settings</key>
493493 <dict>
494494 <key>background</key>
495− <string>#0100000f</string>
495+ <string>#01000000</string>
496496 <key>foreground</key>
497− <string>#0f00000f</string>
497+ <string>#0f000000</string>
498498 </dict>
499499 </dict>
500500 <dict>
@@ -505,9 +505,9 @@
505505 <key>settings</key>
506506 <dict>
507507 <key>background</key>
508− <string>#0900000f</string>
508+ <string>#09000000</string>
509509 <key>foreground</key>
510− <string>#0000000f</string>
510+ <string>#00000000</string>
511511 </dict>
512512 </dict>
513513 <dict>
@@ -518,9 +518,9 @@
518518 <key>settings</key>
519519 <dict>
520520 <key>background</key>
521− <string>#0e00000f</string>
521+ <string>#0e000000</string>
522522 <key>foreground</key>
523− <string>#0f00000f</string>
523+ <string>#0f000000</string>
524524 </dict>
525525 </dict>
526526 <dict>
@@ -531,9 +531,9 @@
531531 <key>settings</key>
532532 <dict>
533533 <key>background</key>
534− <string>#0800000f</string>
534+ <string>#08000000</string>
535535 <key>foreground</key>
536− <string>#0f00000f</string>
536+ <string>#0f000000</string>
537537 </dict>
538538 </dict>
539539 </array>
src/terminal.rs+14−14
@@ -7,11 +7,13 @@ pub fn to_ansi_color(color: highlighting::Color, true_color: bool) -> ansi_term:
77 if color.a == 0 {
88 // Themes can specify one of the user-configurable terminal colors by
99 // encoding them as #RRGGBBAA with AA set to 00 (transparent) and RR set
10− // to the color palette number. The built-in themes ansi-light,
10+ // to the 8-bit color palette number. The built-in themes ansi-light,
1111 // ansi-dark, and base16 use this.
12− Fixed(color.r)
13− } else if color.a == 0x0f {
1412 match color.r {
13+ // For the first 8 colors, use the Color enum to produce ANSI escape
14+ // sequences using codes 30-37 (foreground) and 40-47 (background).
15+ // For example, red foreground is \x1b[31m. This works on terminals
16+ // without 256-color support.
1517 0x00 => Color::Black,
1618 0x01 => Color::Red,
1719 0x02 => Color::Green,
@@ -20,17 +22,15 @@ pub fn to_ansi_color(color: highlighting::Color, true_color: bool) -> ansi_term:
2022 0x05 => Color::Purple,
2123 0x06 => Color::Cyan,
2224 0x07 => Color::White,
23− // TODO: the following should be high-intensity variants of
24− // these colors ("bright black", "bright red", ...).
25− 0x08 => Color::Black,
26− 0x09 => Color::Red,
27− 0x0a => Color::Green,
28− 0x0b => Color::Yellow,
29− 0x0c => Color::Blue,
30− 0x0d => Color::Purple,
31− 0x0e => Color::Cyan,
32− 0x0f => Color::White,
33− _ => unreachable!("The 0x0f color encoding does not allow for codes higher than 0x0f"),
25+ // For all other colors, use Fixed to produce escape sequences using
26+ // codes 38;5 (foreground) and 48;5 (background). For example,
27+ // bright red foreground is \x1b[38;5;9m. This only works on
28+ // terminals with 256-color support.
29+ //
30+ // TODO: When ansi_term adds support for bright variants using codes
31+ // 90-97 (foreground) and 100-107 (background), we should use those
32+ // for values 0x08 to 0x0f and only use Fixed for 0x10 to 0xff.
33+ n => Fixed(n),
3434 }
3535 } else if true_color {
3636 RGB(color.r, color.g, color.b)