diff options
author | Mitchell Kember <mk12360@gmail.com> | 2020-05-02 14:28:08 -0400 |
---|---|---|
committer | David Peter <sharkdp@users.noreply.github.com> | 2020-05-11 19:29:19 +0200 |
commit | f59d00d4c722de05af561666d58d15600c749c1d (patch) | |
tree | ba5ed1e0b6c9c6edd90f031b25553467e06adedd | |
parent | dcfdbf82dd6abaef8047fe0deb7a6a808f15bb15 (diff) |
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.
-rw-r--r-- | assets/themes/base16.tmTheme | 118 | ||||
-rw-r--r-- | src/terminal.rs | 28 |
2 files changed, 73 insertions, 73 deletions
diff --git a/assets/themes/base16.tmTheme b/assets/themes/base16.tmTheme index bb8e6a80..eff2eba4 100644 --- a/assets/themes/base16.tmTheme +++ b/assets/themes/base16.tmTheme @@ -3,8 +3,8 @@ <plist version="1.0"> <dict> <!-- - The colors in this theme are encoded as #RRGGBBAA where RR is an base16 - color number from 00 to 0f, and AA is the special value 0f to indicate + The colors in this theme are encoded as #RRGGBBAA where RR is an ANSI + palette number from 00 to 0f, and AA is the special value 00 to indicate that this encoding is being used. --> <key>author</key> @@ -19,21 +19,21 @@ <key>settings</key> <dict> <key>background</key> - <string>#0000000f</string> + <string>#00000000</string> <key>caret</key> - <string>#0700000f</string> + <string>#07000000</string> <key>foreground</key> - <string>#0700000f</string> + <string>#07000000</string> <key>invisibles</key> - <string>#0800000f</string> + <string>#08000000</string> <key>lineHighlight</key> - <string>#0800000f</string> + <string>#08000000</string> <key>selection</key> - <string>#0b00000f</string> + <string>#0b000000</string> <key>gutter</key> - <string>#0a00000f</string> + <string>#0a000000</string> <key>gutterForeground</key> - <string>#0800000f</string> + <string>#08000000</string> </dict> </dict> <dict> @@ -44,7 +44,7 @@ <key>settings</key> <dict> <key>foreground</key> - <string>#0700000f</string> + <string>#07000000</string> </dict> </dict> <dict> @@ -55,7 +55,7 @@ <key>settings</key> <dict> <key>foreground</key> - <string>#0800000f</string> + <string>#08000000</string> </dict> </dict> <dict> @@ -66,7 +66,7 @@ <key>settings</key> <dict> <key>foreground</key> - <string>#0700000f</string> + <string>#07000000</string> </dict> </dict> <dict> @@ -77,7 +77,7 @@ <key>settings</key> <dict> <key>foreground</key> - <string>#0700000f</string> + <string>#07000000</string> </dict> </dict> <dict> @@ -88,7 +88,7 @@ <key>settings</key> <dict> <key>foreground</key> - <string>#0700000f</string> + <string>#07000000</string> </dict> </dict> <dict> @@ -99,7 +99,7 @@ <key>settings</key> <dict> <key>foreground</key> - <string>#0500000f</string> + <string>#05000000</string> </dict> </dict> <dict> @@ -110,7 +110,7 @@ <key>settings</key> <dict> <key>foreground</key> - <string>#0700000f</string> + <string>#07000000</string> </dict> </dict> <dict> @@ -121,7 +121,7 @@ <key>settings</key> <dict> <key>foreground</key> - <string>#0400000f</string> + <string>#04000000</string> </dict> </dict> <dict> @@ -132,7 +132,7 @@ <key>settings</key> <dict> <key>foreground</key> - <string>#0e00000f</string> + <string>#0e000000</string> </dict> </dict> <dict> @@ -143,7 +143,7 @@ <key>settings</key> <dict> <key>foreground</key> - <string>#0300000f</string> + <string>#03000000</string> </dict> </dict> <dict> @@ -154,7 +154,7 @@ <key>settings</key> <dict> <key>foreground</key> - <string>#0f00000f</string> + <string>#0f000000</string> </dict> </dict> <dict> @@ -165,7 +165,7 @@ <key>settings</key> <dict> <key>foreground</key> - <string>#0400000f</string> + <string>#04000000</string> </dict> </dict> <dict> @@ -176,7 +176,7 @@ <key>settings</key> <dict> <key>foreground</key> - <string>#0500000f</string> + <string>#05000000</string> </dict> </dict> <dict> @@ -187,7 +187,7 @@ <key>settings</key> <dict> <key>foreground</key> - <string>#0600000f</string> + <string>#06000000</string> </dict> </dict> <dict> @@ -198,7 +198,7 @@ <key>settings</key> <dict> <key>foreground</key> - <string>#0200000f</string> + <string>#02000000</string> </dict> </dict> <dict> @@ -209,7 +209,7 @@ <key>settings</key> <dict> <key>foreground</key> - <string>#0900000f</string> + <string>#09000000</string> </dict> </dict> <dict> @@ -220,7 +220,7 @@ <key>settings</key> <dict> <key>foreground</key> - <string>#0900000f</string> + <string>#09000000</string> </dict> </dict> <dict> @@ -231,7 +231,7 @@ <key>settings</key> <dict> <key>foreground</key> - <string>#0900000f</string> + <string>#09000000</string> </dict> </dict> <dict> @@ -242,7 +242,7 @@ <key>settings</key> <dict> <key>foreground</key> - <string>#0900000f</string> + <string>#09000000</string> </dict> </dict> <dict> @@ -253,7 +253,7 @@ <key>settings</key> <dict> <key>foreground</key> - <string>#0100000f</string> + <string>#01000000</string> </dict> </dict> <dict> @@ -264,7 +264,7 @@ <key>settings</key> <dict> <key>foreground</key> - <string>#0900000f</string> + <string>#09000000</string> </dict> </dict> <dict> @@ -275,7 +275,7 @@ <key>settings</key> <dict> <key>foreground</key> - <string>#0400000f</string> + <string>#04000000</string> </dict> </dict> <dict> @@ -286,7 +286,7 @@ <key>settings</key> <dict> <key>foreground</key> - <string>#0500000f</string> + <string>#05000000</string> </dict> </dict> <dict> @@ -297,7 +297,7 @@ <key>settings</key> <dict> <key>foreground</key> - <string>#0900000f</string> + <string>#09000000</string> </dict> </dict> <dict> @@ -310,7 +310,7 @@ <key>fontStyle</key> <string></string> <key>foreground</key> - <string>#0400000f</string> + <string>#04000000</string> </dict> </dict> <dict> @@ -321,7 +321,7 @@ <key>settings</key> <dict> <key>foreground</key> - <string>#0900000f</string> + <string>#09000000</string> </dict> </dict> <dict> @@ -334,7 +334,7 @@ <key>fontStyle</key> <string>bold</string> <key>foreground</key> - <string>#0300000f</string> + <string>#03000000</string> </dict> </dict> <dict> @@ -347,7 +347,7 @@ <key>fontStyle</key> <string>italic</string> <key>foreground</key> - <string>#0500000f</string> + <string>#05000000</string> </dict> </dict> <dict> @@ -358,7 +358,7 @@ <key>settings</key> <dict> <key>foreground</key> - <string>#0200000f</string> + <string>#02000000</string> </dict> </dict> <dict> @@ -369,7 +369,7 @@ <key>settings</key> <dict> <key>foreground</key> - <string>#0100000f</string> + <string>#01000000</string> </dict> </dict> <dict> @@ -380,7 +380,7 @@ <key>settings</key> <dict> <key>foreground</key> - <string>#0900000f</string> + <string>#09000000</string> </dict> </dict> <dict> @@ -391,7 +391,7 @@ <key>settings</key> <dict> <key>foreground</key> - <string>#0900000f</string> + <string>#09000000</string> </dict> </dict> <dict> @@ -402,9 +402,9 @@ <key>settings</key> <dict> <key>background</key> - <string>#0b00000f</string> + <string>#0b000000</string> <key>foreground</key> - <string>#0700000f</string> + <string>#07000000</string> </dict> </dict> <dict> @@ -415,7 +415,7 @@ <key>settings</key> <dict> <key>foreground</key> - <string>#0200000f</string> + <string>#02000000</string> </dict> </dict> <dict> @@ -426,7 +426,7 @@ <key>settings</key> <dict> <key>foreground</key> - <string>#0100000f</string> + <string>#01000000</string> </dict> </dict> <dict> @@ -437,7 +437,7 @@ <key>settings</key> <dict> <key>foreground</key> - <string>#0500000f</string> + <string>#05000000</string> </dict> </dict> <dict> @@ -448,7 +448,7 @@ <key>settings</key> <dict> <key>foreground</key> - <string>#0600000f</string> + <string>#06000000</string> </dict> </dict> <dict> @@ -459,7 +459,7 @@ <key>settings</key> <dict> <key>foreground</key> - <string>#0600000f</string> + <string>#06000000</string> </dict> </dict> <dict> @@ -470,7 +470,7 @@ <key>settings</key> <dict> <key>foreground</key> - <string>#0600000f</string> + <string>#06000000</string> </dict> </dict> <dict> @@ -481,7 +481,7 @@ <key>settings</key> <dict> <key>foreground</key> - <string>#0500000f</string> + <string>#05000000</string> </dict> </dict> <dict> @@ -492,9 +492,9 @@ <key>settings</key> <dict> <key>background</key> - <string>#0100000f</string> + <string>#01000000</string> <key>foreground</key> - <string>#0f00000f</string> + <string>#0f000000</string> </dict> </dict> <dict> @@ -505,9 +505,9 @@ <key>settings</key> <dict> <key>background</key> - <string>#0900000f</string> + <string>#09000000</string> <key>foreground</key> - <string>#0000000f</string> + <string>#00000000</string> </dict> </dict> <dict> @@ -518,9 +518,9 @@ <key>settings</key> <dict> <key>background</key> - <string>#0e00000f</string> + <string>#0e000000</string> <key>foreground</key> - <string>#0f00000f</string> + <string>#0f000000</string> </dict> </dict> <dict> @@ -531,9 +531,9 @@ <key>settings</key> <dict> <key>background</key> - <string>#0800000f</string> + <string>#08000000</string> <key>foreground</key> - <string>#0f00000f</string> + <string>#0f000000</string> </dict> </dict> </array> diff --git a/src/terminal.rs b/src/terminal.rs index 77945d99..c8e2cd48 100644 --- a/src/terminal.rs +++ b/src/terminal.rs @@ -7,11 +7,13 @@ pub fn to_ansi_color(color: highlighting::Color, true_color: bool) -> ansi_term: if color.a == 0 { // Themes can specify one of the user-configurable terminal colors by // 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. - Fixed(color.r) - } else if color.a == 0x0f { 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, 0x01 => Color::Red, 0x02 => Color::Green, @@ -20,17 +22,15 @@ pub fn to_ansi_color(color: highlighting::Color, true_color: bool) -> ansi_term: 0x05 => Color::Purple, 0x06 => Color::Cyan, 0x07 => Color::White, - // TODO: the following should be high-intensity variants of - // these colors ("bright black", "bright red", ...). - 0x08 => Color::Black, - 0x09 => Color::Red, - 0x0a => Color::Green, - 0x0b => Color::Yellow, - 0x0c => Color::Blue, - 0x0d => Color::Purple, - 0x0e => Color::Cyan, - 0x0f => Color::White, - _ => unreachable!("The 0x0f color encoding does not allow for codes higher than 0x0f"), + // For all other colors, use Fixed to produce escape sequences using + // codes 38;5 (foreground) and 48;5 (background). For example, + // bright red foreground is \x1b[38;5;9m. This only works on + // terminals with 256-color support. + // + // TODO: When ansi_term adds support for bright variants using codes + // 90-97 (foreground) and 100-107 (background), we should use those + // for values 0x08 to 0x0f and only use Fixed for 0x10 to 0xff. + n => Fixed(n), } } else if true_color { RGB(color.r, color.g, color.b) |