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.
pull/986/head
Mitchell Kember 4 years ago committed by David Peter
parent dcfdbf82dd
commit f59d00d4c7

@ -3,8 +3,8 @@
<plist version="1.0"> <plist version="1.0">
<dict> <dict>
<!-- <!--
The colors in this theme are encoded as #RRGGBBAA where RR is an base16 The colors in this theme are encoded as #RRGGBBAA where RR is an ANSI
color number from 00 to 0f, and AA is the special value 0f to indicate palette number from 00 to 0f, and AA is the special value 00 to indicate
that this encoding is being used. that this encoding is being used.
--> -->
<key>author</key> <key>author</key>
@ -19,21 +19,21 @@
<key>settings</key> <key>settings</key>
<dict> <dict>
<key>background</key> <key>background</key>
<string>#0000000f</string> <string>#00000000</string>
<key>caret</key> <key>caret</key>
<string>#0700000f</string> <string>#07000000</string>
<key>foreground</key> <key>foreground</key>
<string>#0700000f</string> <string>#07000000</string>
<key>invisibles</key> <key>invisibles</key>
<string>#0800000f</string> <string>#08000000</string>
<key>lineHighlight</key> <key>lineHighlight</key>
<string>#0800000f</string> <string>#08000000</string>
<key>selection</key> <key>selection</key>
<string>#0b00000f</string> <string>#0b000000</string>
<key>gutter</key> <key>gutter</key>
<string>#0a00000f</string> <string>#0a000000</string>
<key>gutterForeground</key> <key>gutterForeground</key>
<string>#0800000f</string> <string>#08000000</string>
</dict> </dict>
</dict> </dict>
<dict> <dict>
@ -44,7 +44,7 @@
<key>settings</key> <key>settings</key>
<dict> <dict>
<key>foreground</key> <key>foreground</key>
<string>#0700000f</string> <string>#07000000</string>
</dict> </dict>
</dict> </dict>
<dict> <dict>
@ -55,7 +55,7 @@
<key>settings</key> <key>settings</key>
<dict> <dict>
<key>foreground</key> <key>foreground</key>
<string>#0800000f</string> <string>#08000000</string>
</dict> </dict>
</dict> </dict>
<dict> <dict>
@ -66,7 +66,7 @@
<key>settings</key> <key>settings</key>
<dict> <dict>
<key>foreground</key> <key>foreground</key>
<string>#0700000f</string> <string>#07000000</string>
</dict> </dict>
</dict> </dict>
<dict> <dict>
@ -77,7 +77,7 @@
<key>settings</key> <key>settings</key>
<dict> <dict>
<key>foreground</key> <key>foreground</key>
<string>#0700000f</string> <string>#07000000</string>
</dict> </dict>
</dict> </dict>
<dict> <dict>
@ -88,7 +88,7 @@
<key>settings</key> <key>settings</key>
<dict> <dict>
<key>foreground</key> <key>foreground</key>
<string>#0700000f</string> <string>#07000000</string>
</dict> </dict>
</dict> </dict>
<dict> <dict>
@ -99,7 +99,7 @@
<key>settings</key> <key>settings</key>
<dict> <dict>
<key>foreground</key> <key>foreground</key>
<string>#0500000f</string> <string>#05000000</string>
</dict> </dict>
</dict> </dict>
<dict> <dict>
@ -110,7 +110,7 @@
<key>settings</key> <key>settings</key>
<dict> <dict>
<key>foreground</key> <key>foreground</key>
<string>#0700000f</string> <string>#07000000</string>
</dict> </dict>
</dict> </dict>
<dict> <dict>
@ -121,7 +121,7 @@
<key>settings</key> <key>settings</key>
<dict> <dict>
<key>foreground</key> <key>foreground</key>
<string>#0400000f</string> <string>#04000000</string>
</dict> </dict>
</dict> </dict>
<dict> <dict>
@ -132,7 +132,7 @@
<key>settings</key> <key>settings</key>
<dict> <dict>
<key>foreground</key> <key>foreground</key>
<string>#0e00000f</string> <string>#0e000000</string>
</dict> </dict>
</dict> </dict>
<dict> <dict>
@ -143,7 +143,7 @@
<key>settings</key> <key>settings</key>
<dict> <dict>
<key>foreground</key> <key>foreground</key>
<string>#0300000f</string> <string>#03000000</string>
</dict> </dict>
</dict> </dict>
<dict> <dict>
@ -154,7 +154,7 @@
<key>settings</key> <key>settings</key>
<dict> <dict>
<key>foreground</key> <key>foreground</key>
<string>#0f00000f</string> <string>#0f000000</string>
</dict> </dict>
</dict> </dict>
<dict> <dict>
@ -165,7 +165,7 @@
<key>settings</key> <key>settings</key>
<dict> <dict>
<key>foreground</key> <key>foreground</key>
<string>#0400000f</string> <string>#04000000</string>
</dict> </dict>
</dict> </dict>
<dict> <dict>
@ -176,7 +176,7 @@
<key>settings</key> <key>settings</key>
<dict> <dict>
<key>foreground</key> <key>foreground</key>
<string>#0500000f</string> <string>#05000000</string>
</dict> </dict>
</dict> </dict>
<dict> <dict>
@ -187,7 +187,7 @@
<key>settings</key> <key>settings</key>
<dict> <dict>
<key>foreground</key> <key>foreground</key>
<string>#0600000f</string> <string>#06000000</string>
</dict> </dict>
</dict> </dict>
<dict> <dict>
@ -198,7 +198,7 @@
<key>settings</key> <key>settings</key>
<dict> <dict>
<key>foreground</key> <key>foreground</key>
<string>#0200000f</string> <string>#02000000</string>
</dict> </dict>
</dict> </dict>
<dict> <dict>
@ -209,7 +209,7 @@
<key>settings</key> <key>settings</key>
<dict> <dict>
<key>foreground</key> <key>foreground</key>
<string>#0900000f</string> <string>#09000000</string>
</dict> </dict>
</dict> </dict>
<dict> <dict>
@ -220,7 +220,7 @@
<key>settings</key> <key>settings</key>
<dict> <dict>
<key>foreground</key> <key>foreground</key>
<string>#0900000f</string> <string>#09000000</string>
</dict> </dict>
</dict> </dict>
<dict> <dict>
@ -231,7 +231,7 @@
<key>settings</key> <key>settings</key>
<dict> <dict>
<key>foreground</key> <key>foreground</key>
<string>#0900000f</string> <string>#09000000</string>
</dict> </dict>
</dict> </dict>
<dict> <dict>
@ -242,7 +242,7 @@
<key>settings</key> <key>settings</key>
<dict> <dict>
<key>foreground</key> <key>foreground</key>
<string>#0900000f</string> <string>#09000000</string>
</dict> </dict>
</dict> </dict>
<dict> <dict>
@ -253,7 +253,7 @@
<key>settings</key> <key>settings</key>
<dict> <dict>
<key>foreground</key> <key>foreground</key>
<string>#0100000f</string> <string>#01000000</string>
</dict> </dict>
</dict> </dict>
<dict> <dict>
@ -264,7 +264,7 @@
<key>settings</key> <key>settings</key>
<dict> <dict>
<key>foreground</key> <key>foreground</key>
<string>#0900000f</string> <string>#09000000</string>
</dict> </dict>
</dict> </dict>
<dict> <dict>
@ -275,7 +275,7 @@
<key>settings</key> <key>settings</key>
<dict> <dict>
<key>foreground</key> <key>foreground</key>
<string>#0400000f</string> <string>#04000000</string>
</dict> </dict>
</dict> </dict>
<dict> <dict>
@ -286,7 +286,7 @@
<key>settings</key> <key>settings</key>
<dict> <dict>
<key>foreground</key> <key>foreground</key>
<string>#0500000f</string> <string>#05000000</string>
</dict> </dict>
</dict> </dict>
<dict> <dict>
@ -297,7 +297,7 @@
<key>settings</key> <key>settings</key>
<dict> <dict>
<key>foreground</key> <key>foreground</key>
<string>#0900000f</string> <string>#09000000</string>
</dict> </dict>
</dict> </dict>
<dict> <dict>
@ -310,7 +310,7 @@
<key>fontStyle</key> <key>fontStyle</key>
<string></string> <string></string>
<key>foreground</key> <key>foreground</key>
<string>#0400000f</string> <string>#04000000</string>
</dict> </dict>
</dict> </dict>
<dict> <dict>
@ -321,7 +321,7 @@
<key>settings</key> <key>settings</key>
<dict> <dict>
<key>foreground</key> <key>foreground</key>
<string>#0900000f</string> <string>#09000000</string>
</dict> </dict>
</dict> </dict>
<dict> <dict>
@ -334,7 +334,7 @@
<key>fontStyle</key> <key>fontStyle</key>
<string>bold</string> <string>bold</string>
<key>foreground</key> <key>foreground</key>
<string>#0300000f</string> <string>#03000000</string>
</dict> </dict>
</dict> </dict>
<dict> <dict>
@ -347,7 +347,7 @@
<key>fontStyle</key> <key>fontStyle</key>
<string>italic</string> <string>italic</string>
<key>foreground</key> <key>foreground</key>
<string>#0500000f</string> <string>#05000000</string>
</dict> </dict>
</dict> </dict>
<dict> <dict>
@ -358,7 +358,7 @@
<key>settings</key> <key>settings</key>
<dict> <dict>
<key>foreground</key> <key>foreground</key>
<string>#0200000f</string> <string>#02000000</string>
</dict> </dict>
</dict> </dict>
<dict> <dict>
@ -369,7 +369,7 @@
<key>settings</key> <key>settings</key>
<dict> <dict>
<key>foreground</key> <key>foreground</key>
<string>#0100000f</string> <string>#01000000</string>
</dict> </dict>
</dict> </dict>
<dict> <dict>
@ -380,7 +380,7 @@
<key>settings</key> <key>settings</key>
<dict> <dict>
<key>foreground</key> <key>foreground</key>
<string>#0900000f</string> <string>#09000000</string>
</dict> </dict>
</dict> </dict>
<dict> <dict>
@ -391,7 +391,7 @@
<key>settings</key> <key>settings</key>
<dict> <dict>
<key>foreground</key> <key>foreground</key>
<string>#0900000f</string> <string>#09000000</string>
</dict> </dict>
</dict> </dict>
<dict> <dict>
@ -402,9 +402,9 @@
<key>settings</key> <key>settings</key>
<dict> <dict>
<key>background</key> <key>background</key>
<string>#0b00000f</string> <string>#0b000000</string>
<key>foreground</key> <key>foreground</key>
<string>#0700000f</string> <string>#07000000</string>
</dict> </dict>
</dict> </dict>
<dict> <dict>
@ -415,7 +415,7 @@
<key>settings</key> <key>settings</key>
<dict> <dict>
<key>foreground</key> <key>foreground</key>
<string>#0200000f</string> <string>#02000000</string>
</dict> </dict>
</dict> </dict>
<dict> <dict>
@ -426,7 +426,7 @@
<key>settings</key> <key>settings</key>
<dict> <dict>
<key>foreground</key> <key>foreground</key>
<string>#0100000f</string> <string>#01000000</string>
</dict> </dict>
</dict> </dict>
<dict> <dict>
@ -437,7 +437,7 @@
<key>settings</key> <key>settings</key>
<dict> <dict>
<key>foreground</key> <key>foreground</key>
<string>#0500000f</string> <string>#05000000</string>
</dict> </dict>
</dict> </dict>
<dict> <dict>
@ -448,7 +448,7 @@
<key>settings</key> <key>settings</key>
<dict> <dict>
<key>foreground</key> <key>foreground</key>
<string>#0600000f</string> <string>#06000000</string>
</dict> </dict>
</dict> </dict>
<dict> <dict>
@ -459,7 +459,7 @@
<key>settings</key> <key>settings</key>
<dict> <dict>
<key>foreground</key> <key>foreground</key>
<string>#0600000f</string> <string>#06000000</string>
</dict> </dict>
</dict> </dict>
<dict> <dict>
@ -470,7 +470,7 @@
<key>settings</key> <key>settings</key>
<dict> <dict>
<key>foreground</key> <key>foreground</key>
<string>#0600000f</string> <string>#06000000</string>
</dict> </dict>
</dict> </dict>
<dict> <dict>
@ -481,7 +481,7 @@
<key>settings</key> <key>settings</key>
<dict> <dict>
<key>foreground</key> <key>foreground</key>
<string>#0500000f</string> <string>#05000000</string>
</dict> </dict>
</dict> </dict>
<dict> <dict>
@ -492,9 +492,9 @@
<key>settings</key> <key>settings</key>
<dict> <dict>
<key>background</key> <key>background</key>
<string>#0100000f</string> <string>#01000000</string>
<key>foreground</key> <key>foreground</key>
<string>#0f00000f</string> <string>#0f000000</string>
</dict> </dict>
</dict> </dict>
<dict> <dict>
@ -505,9 +505,9 @@
<key>settings</key> <key>settings</key>
<dict> <dict>
<key>background</key> <key>background</key>
<string>#0900000f</string> <string>#09000000</string>
<key>foreground</key> <key>foreground</key>
<string>#0000000f</string> <string>#00000000</string>
</dict> </dict>
</dict> </dict>
<dict> <dict>
@ -518,9 +518,9 @@
<key>settings</key> <key>settings</key>
<dict> <dict>
<key>background</key> <key>background</key>
<string>#0e00000f</string> <string>#0e000000</string>
<key>foreground</key> <key>foreground</key>
<string>#0f00000f</string> <string>#0f000000</string>
</dict> </dict>
</dict> </dict>
<dict> <dict>
@ -531,9 +531,9 @@
<key>settings</key> <key>settings</key>
<dict> <dict>
<key>background</key> <key>background</key>
<string>#0800000f</string> <string>#08000000</string>
<key>foreground</key> <key>foreground</key>
<string>#0f00000f</string> <string>#0f000000</string>
</dict> </dict>
</dict> </dict>
</array> </array>

@ -7,11 +7,13 @@ pub fn to_ansi_color(color: highlighting::Color, true_color: bool) -> ansi_term:
if color.a == 0 { if color.a == 0 {
// Themes can specify one of the user-configurable terminal colors by // Themes can specify one of the user-configurable terminal colors by
// encoding them as #RRGGBBAA with AA set to 00 (transparent) and RR set // encoding them as #RRGGBBAA with AA set to 00 (transparent) and RR set
// to the color palette number. The built-in themes ansi-light, // to the 8-bit color palette number. The built-in themes ansi-light,
// ansi-dark, and base16 use this. // ansi-dark, and base16 use this.
Fixed(color.r)
} else if color.a == 0x0f {
match color.r { match color.r {
// For the first 8 colors, use the Color enum to produce ANSI escape
// sequences using codes 30-37 (foreground) and 40-47 (background).
// For example, red foreground is \x1b[31m. This works on terminals
// without 256-color support.
0x00 => Color::Black, 0x00 => Color::Black,
0x01 => Color::Red, 0x01 => Color::Red,
0x02 => Color::Green, 0x02 => Color::Green,
@ -20,17 +22,15 @@ pub fn to_ansi_color(color: highlighting::Color, true_color: bool) -> ansi_term:
0x05 => Color::Purple, 0x05 => Color::Purple,
0x06 => Color::Cyan, 0x06 => Color::Cyan,
0x07 => Color::White, 0x07 => Color::White,
// TODO: the following should be high-intensity variants of // For all other colors, use Fixed to produce escape sequences using
// these colors ("bright black", "bright red", ...). // codes 38;5 (foreground) and 48;5 (background). For example,
0x08 => Color::Black, // bright red foreground is \x1b[38;5;9m. This only works on
0x09 => Color::Red, // terminals with 256-color support.
0x0a => Color::Green, //
0x0b => Color::Yellow, // TODO: When ansi_term adds support for bright variants using codes
0x0c => Color::Blue, // 90-97 (foreground) and 100-107 (background), we should use those
0x0d => Color::Purple, // for values 0x08 to 0x0f and only use Fixed for 0x10 to 0xff.
0x0e => Color::Cyan, n => Fixed(n),
0x0f => Color::White,
_ => unreachable!("The 0x0f color encoding does not allow for codes higher than 0x0f"),
} }
} else if true_color { } else if true_color {
RGB(color.r, color.g, color.b) RGB(color.r, color.g, color.b)

Loading…
Cancel
Save