Use 4-bit ANSI codes for base16 theme

closes #865
pull/940/head
sharkdp 5 years ago committed by David Peter
parent 37831cdcb3
commit 319ab779ee

BIN
assets/themes.bin vendored

Binary file not shown.

@ -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 ANSI The colors in this theme are encoded as #RRGGBBAA where RR is an base16
palette number from 00 to 0f, and AA is the special value 00 to indicate color number from 00 to 0f, and AA is the special value 0f 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>#00000000</string> <string>#0000000f</string>
<key>caret</key> <key>caret</key>
<string>#07000000</string> <string>#0700000f</string>
<key>foreground</key> <key>foreground</key>
<string>#07000000</string> <string>#0700000f</string>
<key>invisibles</key> <key>invisibles</key>
<string>#08000000</string> <string>#0800000f</string>
<key>lineHighlight</key> <key>lineHighlight</key>
<string>#08000000</string> <string>#0800000f</string>
<key>selection</key> <key>selection</key>
<string>#0b000000</string> <string>#0b00000f</string>
<key>gutter</key> <key>gutter</key>
<string>#0a000000</string> <string>#0a00000f</string>
<key>gutterForeground</key> <key>gutterForeground</key>
<string>#08000000</string> <string>#0800000f</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>#07000000</string> <string>#0700000f</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>#08000000</string> <string>#0800000f</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>#07000000</string> <string>#0700000f</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>#07000000</string> <string>#0700000f</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>#07000000</string> <string>#0700000f</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>#05000000</string> <string>#0500000f</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>#07000000</string> <string>#0700000f</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>#04000000</string> <string>#0400000f</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>#0e000000</string> <string>#0e00000f</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>#03000000</string> <string>#0300000f</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>#0f000000</string> <string>#0f00000f</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>#04000000</string> <string>#0400000f</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>#05000000</string> <string>#0500000f</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>#06000000</string> <string>#0600000f</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>#02000000</string> <string>#0200000f</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>#09000000</string> <string>#0900000f</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>#09000000</string> <string>#0900000f</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>#09000000</string> <string>#0900000f</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>#09000000</string> <string>#0900000f</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>#01000000</string> <string>#0100000f</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>#09000000</string> <string>#0900000f</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>#04000000</string> <string>#0400000f</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>#05000000</string> <string>#0500000f</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>#09000000</string> <string>#0900000f</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>#04000000</string> <string>#0400000f</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>#09000000</string> <string>#0900000f</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>#03000000</string> <string>#0300000f</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>#05000000</string> <string>#0500000f</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>#02000000</string> <string>#0200000f</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>#01000000</string> <string>#0100000f</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>#09000000</string> <string>#0900000f</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>#09000000</string> <string>#0900000f</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>#0b000000</string> <string>#0b00000f</string>
<key>foreground</key> <key>foreground</key>
<string>#07000000</string> <string>#0700000f</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>#02000000</string> <string>#0200000f</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>#01000000</string> <string>#0100000f</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>#05000000</string> <string>#0500000f</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>#06000000</string> <string>#0600000f</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>#06000000</string> <string>#0600000f</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>#06000000</string> <string>#0600000f</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>#05000000</string> <string>#0500000f</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>#01000000</string> <string>#0100000f</string>
<key>foreground</key> <key>foreground</key>
<string>#0f000000</string> <string>#0f00000f</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>#09000000</string> <string>#0900000f</string>
<key>foreground</key> <key>foreground</key>
<string>#00000000</string> <string>#0000000f</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>#0e000000</string> <string>#0e00000f</string>
<key>foreground</key> <key>foreground</key>
<string>#0f000000</string> <string>#0f00000f</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>#08000000</string> <string>#0800000f</string>
<key>foreground</key> <key>foreground</key>
<string>#0f000000</string> <string>#0f00000f</string>
</dict> </dict>
</dict> </dict>
</array> </array>

@ -1,15 +1,37 @@
use ansi_term::Colour::{Fixed, RGB}; use ansi_term::Color::{self, Fixed, RGB};
use ansi_term::{self, Style}; use ansi_term::{self, Style};
use syntect::highlighting::{self, FontStyle}; use syntect::highlighting::{self, FontStyle};
pub fn to_ansi_color(color: highlighting::Color, true_color: bool) -> ansi_term::Colour { pub fn to_ansi_color(color: highlighting::Color, true_color: bool) -> ansi_term::Color {
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 color palette number. The built-in themes ansi-light,
// ansi-dark, and base16 use this. // ansi-dark, and base16 use this.
Fixed(color.r) Fixed(color.r)
} else if color.a == 0x0f {
match color.r {
0x00 => Color::Black,
0x01 => Color::Red,
0x02 => Color::Green,
0x03 => Color::Yellow,
0x04 => Color::Blue,
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")
}
} else if true_color { } else if true_color {
RGB(color.r, color.g, color.b) RGB(color.r, color.g, color.b)
} else { } else {

Loading…
Cancel
Save