summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsharkdp <davidpeter@web.de>2020-04-22 08:56:07 +0200
committerDavid Peter <sharkdp@users.noreply.github.com>2020-04-22 10:22:11 +0200
commit319ab779ee6bc8954e7beb2ae34c43d9f327322e (patch)
tree894827abe4c00fe3dae925b015093b4a2ad7e077
parent37831cdcb3cd5970fb07274a6eaf9338f15b9569 (diff)
Use 4-bit ANSI codes for base16 theme
closes #865
-rw-r--r--assets/themes.binbin16785 -> 16882 bytes
-rw-r--r--assets/themes/base16.tmTheme118
-rw-r--r--src/terminal.rs26
3 files changed, 83 insertions, 61 deletions
diff --git a/assets/themes.bin b/assets/themes.bin
index 484b3fbc..1186d8b9 100644
--- a/assets/themes.bin
+++ b/assets/themes.bin
Binary files differ
diff --git a/assets/themes/base16.tmTheme b/assets/themes/base16.tmTheme
index eff2eba4..bb8e6a80 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 ANSI
- palette number from 00 to 0f, and AA is the special value 00 to indicate
+ 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
that this encoding is being used.
-->
<key>author</key>
@@ -19,21 +19,21 @@
<key>settings</key>
<dict>
<key>background</key>
- <string>#00000000</string>
+ <string>#0000000f</string>
<key>caret</key>
- <string>#07000000</string>
+ <string>#0700000f</string>
<key>foreground</key>
- <string>#07000000</string>
+ <string>#0700000f</string>
<key>invisibles</key>
- <string>#08000000</string>
+ <string>#0800000f</string>
<key>lineHighlight</key>
- <string>#08000000</string>
+ <string>#0800000f</string>
<key>selection</key>
- <string>#0b000000</string>
+ <string>#0b00000f</string>
<key>gutter</key>
- <string>#0a000000</string>
+ <string>#0a00000f</string>
<key>gutterForeground</key>
- <string>#08000000</string>
+ <string>#0800000f</string>
</dict>
</dict>
<dict>
@@ -44,7 +44,7 @@
<key>settings</key>
<dict>
<key>foreground</key>
- <string>#07000000</string>
+ <string>#0700000f</string>
</dict>
</dict>
<dict>
@@ -55,7 +55,7 @@
<key>settings</key>
<dict>
<key>foreground</key>
- <string>#08000000</string>
+ <string>#0800000f</string>
</dict>
</dict>
<dict>
@@ -66,7 +66,7 @@
<key>settings</key>
<dict>
<key>foreground</key>
- <string>#07000000</string>
+ <string>#0700000f</string>
</dict>
</dict>
<dict>
@@ -77,7 +77,7 @@
<key>settings</key>
<dict>
<key>foreground</key>
- <string>#07000000</string>
+ <string>#0700000f</string>
</dict>
</dict>
<dict>
@@ -88,7 +88,7 @@
<key>settings</key>
<dict>
<key>foreground</key>
- <string>#07000000</string>
+ <string>#0700000f</string>
</dict>
</dict>
<dict>
@@ -99,7 +99,7 @@
<key>settings</key>
<dict>
<key>foreground</key>
- <string>#05000000</string>
+ <string>#0500000f</string>
</dict>
</dict>
<dict>
@@ -110,7 +110,7 @@
<key>settings</key>
<dict>
<key>foreground</key>
- <string>#07000000</string>
+ <string>#0700000f</string>
</dict>
</dict>
<dict>
@@ -121,7 +121,7 @@
<key>settings</key>
<dict>
<key>foreground</key>
- <string>#04000000</string>
+ <string>#0400000f</string>
</dict>
</dict>
<dict>
@@ -132,7 +132,7 @@
<key>settings</key>
<dict>
<key>foreground</key>
- <string>#0e000000</string>
+ <string>#0e00000f</string>
</dict>
</dict>
<dict>
@@ -143,7 +143,7 @@
<key>settings</key>
<dict>
<key>foreground</key>
- <string>#03000000</string>
+ <string>#0300000f</string>
</dict>
</dict>
<dict>
@@ -154,7 +154,7 @@
<key>settings</key>
<dict>
<key>foreground</key>
- <string>#0f000000</string>
+ <string>#0f00000f</string>
</dict>
</dict>
<dict>
@@ -165,7 +165,7 @@
<key>settings</key>
<dict>
<key>foreground</key>
- <string>#04000000</string>
+ <string>#0400000f</string>
</dict>
</dict>
<dict>
@@ -176,7 +176,7 @@
<key>settings</key>
<dict>
<key>foreground</key>
- <string>#05000000</string>
+ <string>#0500000f</string>
</dict>
</dict>
<dict>
@@ -187,7 +187,7 @@
<key>settings</key>
<dict>
<key>foreground</key>
- <string>#06000000</string>
+ <string>#0600000f</string>
</dict>
</dict>
<dict>
@@ -198,7 +198,7 @@
<key>settings</key>
<dict>
<key>foreground</key>
- <string>#02000000</string>
+ <string>#0200000f</string>
</dict>
</dict>
<dict>
@@ -209,7 +209,7 @@
<key>settings</key>
<dict>
<key>foreground</key>
- <string>#09000000</string>
+ <string>#0900000f</string>
</dict>
</dict>
<dict>
@@ -220,7 +220,7 @@
<key>settings</key>
<dict>
<key>foreground</key>
- <string>#09000000</string>
+ <string>#0900000f</string>
</dict>
</dict>
<dict>
@@ -231,7 +231,7 @@
<key>settings</key>
<dict>
<key>foreground</key>
- <string>#09000000</string>
+ <string>#0900000f</string>
</dict>
</dict>
<dict>
@@ -242,7 +242,7 @@
<key>settings</key>
<dict>
<key>foreground</key>
- <string>#09000000</string>
+ <string>#0900000f</string>
</dict>
</dict>
<dict>
@@ -253,7 +253,7 @@
<key>settings</key>
<dict>
<key>foreground</key>
- <string>#01000000</string>
+ <string>#0100000f</string>
</dict>
</dict>
<dict>
@@ -264,7 +264,7 @@
<key>settings</key>
<dict>
<key>foreground</key>
- <string>#09000000</string>
+ <string>#0900000f</string>
</dict>
</dict>
<dict>
@@ -275,7 +275,7 @@
<key>settings</key>
<dict>
<key>foreground</key>
- <string>#04000000</string>
+ <string>#0400000f</string>
</dict>
</dict>
<dict>
@@ -286,7 +286,7 @@
<key>settings</key>
<dict>
<key>foreground</key>
- <string>#05000000</string>
+ <string>#0500000f</string>
</dict>
</dict>
<dict>
@@ -297,7 +297,7 @@
<key>settings</key>
<dict>
<key>foreground</key>
- <string>#09000000</string>
+ <string>#0900000f</string>
</dict>
</dict>
<dict>
@@ -310,7 +310,7 @@
<key>fontStyle</key>
<string></string>
<key>foreground</key>
- <string>#04000000</string>
+ <string>#0400000f</string>
</dict>
</dict>
<dict>
@@ -321,7 +321,7 @@
<key>settings</key>
<dict>
<key>foreground</key>
- <string>#09000000</string>
+ <string>#0900000f</string>
</dict>
</dict>
<dict>
@@ -334,7 +334,7 @@
<key>fontStyle</key>
<string>bold</string>
<key>foreground</key>
- <string>#03000000</string>
+ <string>#0300000f</string>
</dict>
</dict>
<dict>
@@ -347,7 +347,7 @@
<key>fontStyle</key>
<string>italic</string>
<key>foreground</key>
- <string>#05000000</string>
+ <string>#0500000f</string>
</dict>
</dict>
<dict>
@@ -358,7 +358,7 @@
<key>settings</key>
<dict>
<key>foreground</key>
- <string>#02000000</string>
+ <string>#0200000f</string>
</dict>
</dict>
<dict>
@@ -369,7 +369,7 @@
<key>settings</key>
<dict>
<key>foreground</key>
- <string>#01000000</string>
+ <string>#0100000f</string>
</dict>
</dict>
<dict>
@@ -380,7 +380,7 @@
<key>settings</key>
<dict>
<key>foreground</key>
- <string>#09000000</string>
+ <string>#0900000f</string>
</dict>
</dict>
<dict>
@@ -391,7 +391,7 @@
<key>settings</key>
<dict>
<key>foreground</key>
- <string>#09000000</string>
+ <string>#0900000f</string>
</dict>
</dict>
<dict>
@@ -402,9 +402,9 @@
<key>settings</key>
<dict>
<key>background</key>
- <string>#0b000000</string>
+ <string>#0b00000f</string>
<key>foreground</key>
- <string>#07000000</string>
+ <string>#0700000f</string>
</dict>
</dict>
<dict>
@@ -415,7 +415,7 @@
<key>settings</key>
<dict>
<key>foreground</key>
- <string>#02000000</string>
+ <string>#0200000f</string>
</dict>
</dict>
<dict>
@@ -426,7 +426,7 @@
<key>settings</key>
<dict>
<key>foreground</key>
- <string>#01000000</string>
+ <string>#0100000f</string>
</dict>
</dict>
<dict>
@@ -437,7 +437,7 @@
<key>settings</key>
<dict>
<key>foreground</key>
- <string>#05000000</string>
+ <string>#0500000f</string>
</dict>
</dict>
<dict>
@@ -448,7 +448,7 @@
<key>settings</key>
<dict>
<key>foreground</key>
- <string>#06000000</string>
+ <string>#0600000f</string>
</dict>
</dict>
<dict>
@@ -459,7 +459,7 @@
<key>settings</key>
<dict>
<key>foreground</key>
- <string>#06000000</string>
+ <string>#0600000f</string>
</dict>
</dict>
<dict>
@@ -470,7 +470,7 @@
<key>settings</key>
<dict>
<key>foreground</key>
- <string>#06000000</string>
+ <string>#0600000f</string>
</dict>
</dict>
<dict>
@@ -481,7 +481,7 @@
<key>settings</key>
<dict>
<key>foreground</key>
- <string>#05000000</string>
+ <string>#0500000f</string>
</dict>
</dict>
<dict>
@@ -492,9 +492,9 @@
<key>settings</key>
<dict>
<key>background</key>
- <string>#01000000</string>
+ <string>#0100000f</string>
<key>foreground</key>
- <string>#0f000000</string>
+ <string>#0f00000f</string>
</dict>
</dict>
<dict>
@@ -505,9 +505,9 @@
<key>settings</key>
<dict>
<key>background</key>
- <string>#09000000</string>
+ <string>#0900000f</string>
<key>foreground</key>
- <string>#00000000</string>
+ <string>#0000000f</string>
</dict>
</dict>
<dict>
@@ -518,9 +518,9 @@
<key>settings</key>
<dict>
<key>background</key>
- <string>#0e000000</string>
+ <string>#0e00000f</string>
<key>foreground</key>
- <string>#0f000000</string>
+ <string>#0f00000f</string>
</dict>
</dict>
<dict>
@@ -531,9 +531,9 @@
<key>settings</key>
<dict>
<key>background</key>
- <string>#08000000</string>
+ <string>#0800000f</string>
<key>foreground</key>
- <string>#0f000000</string>
+ <string>#0f00000f</string>
</dict>
</dict>
</array>
diff --git a/src/terminal.rs b/src/terminal.rs
index 981bf3b2..9f2c4dd1 100644
--- a/src/terminal.rs
+++ b/src/terminal.rs
@@ -1,15 +1,37 @@
-use ansi_term::Colour::{Fixed, RGB};
+use ansi_term::Color::{self, Fixed, RGB};
use ansi_term::{self, Style};
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 {
// 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,
// ansi-dark, and base16 use this.
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 {
RGB(color.r, color.g, color.b)
} else {