diff --git a/CHANGELOG.md b/CHANGELOG.md index d51da1de..f604c0a8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,7 @@ ## New themes - Gruvbox, see #1069 (@kyleondy) +- base16-256 for [base16-shell](https://github.com/chriskempson/base16-shell) users, see #1111 (@mk12) ## `bat` as a library diff --git a/README.md b/README.md index 4bd108ad..ef0d68e2 100644 --- a/README.md +++ b/README.md @@ -354,6 +354,26 @@ light background, some themes like `GitHub` or `OneHalfLight` will work better f You can also use a custom theme by following the ['Adding new themes' section below](https://github.com/sharkdp/bat#adding-new-themes). +### 8-bit themes + +`bat` has four themes that always use [8-bit colors](https://en.wikipedia.org/wiki/ANSI_escape_code#Colors), +even when truecolor support is available: + +- `ansi-dark` looks decent on any terminal with a dark background. It uses 3-bit colors: black, red, + green, yellow, blue, magenta, cyan, and white. +- `ansi-light` is like `ansi-dark`, but for terminals with a light background. +- `base16` is designed for [base16](https://github.com/chriskempson/base16) terminal themes. It uses + 4-bit colors (3-bit colors plus bright variants) in accordance with the + [base16 styling guidelines](https://github.com/chriskempson/base16/blob/master/styling.md). +- `base16-256` is designed for [base16-shell](https://github.com/chriskempson/base16-shell). + It replaces certain bright colors with 8-bit colors from 16 to 21. **Do not** use this simply + because you have a 256-color terminal but are not using base16-shell. + +Although these themes are more restricted, they have two advantages over truecolor themes: + +- They harmonize better with other terminal software using 3-bit or 4-bit colors. +- When you change your terminal theme, `bat` output already on the screen will update to match. + ### Output style You can use the `--style` option to control the appearance of `bat`s output. @@ -554,9 +574,10 @@ bat() { ### Terminals & colors -`bat` handles terminals *with* and *without* truecolor support. However, the colors in the syntax -highlighting themes are not optimized for 8-bit colors and it is therefore strongly recommended -that you use a terminal with 24-bit truecolor support (`terminator`, `konsole`, `iTerm2`, ...). +`bat` handles terminals *with* and *without* truecolor support. However, the colors in most syntax +highlighting themes are not optimized for 8-bit colors. It is therefore strongly recommended +that you use a terminal with 24-bit truecolor support (`terminator`, `konsole`, `iTerm2`, ...), +or use one of the basic [8-bit themes](#8-bit-themes) designed for a restricted set of colors. See [this article](https://gist.github.com/XVilka/8346728) for more details and a full list of terminals with truecolor support. diff --git a/assets/themes/base16-256.tmTheme b/assets/themes/base16-256.tmTheme new file mode 100644 index 00000000..a4547e56 --- /dev/null +++ b/assets/themes/base16-256.tmTheme @@ -0,0 +1,551 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> +<plist version="1.0"> + <dict> + <!-- + Most base16 users should use the base16 theme. This theme, base16-256, + is for users who configure their terminal with a 256-color variant of a + base16 theme, and who use base16-shell. DO NOT use this theme simply + because your terminal supports 256 colors. + + base16: https://github.com/chriskempson/base16 + base16-shell: https://github.com/chriskempson/base16-shell + + The colors in this theme are encoded as #RRGGBBAA where RR is an ANSI + palette number from 00 to ff (the 256 terminal colors), and AA is the + special value 00 to indicate this encoding is being used. + --> + <key>author</key> + <string>Template: Chris Kempson, Scheme: Mitchell Kember</string> + <key>name</key> + <string>Base16 256</string> + <key>colorSpaceName</key> + <string>sRGB</string> + <key>settings</key> + <array> + <dict> + <key>settings</key> + <dict> + <key>background</key> + <string>#00000000</string> + <key>caret</key> + <string>#07000000</string> + <key>foreground</key> + <string>#07000000</string> + <key>invisibles</key> + <string>#08000000</string> + <key>lineHighlight</key> + <string>#08000000</string> + <key>selection</key> + <string>#13000000</string> + <key>gutter</key> + <string>#12000000</string> + <key>gutterForeground</key> + <string>#08000000</string> + </dict> + </dict> + <dict> + <key>name</key> + <string>Text</string> + <key>scope</key> + <string>variable.parameter.function</string> + <key>settings</key> + <dict> + <key>foreground</key> + <string>#07000000</string> + </dict> + </dict> + <dict> + <key>name</key> + <string>Comments</string> + <key>scope</key> + <string>comment, punctuation.definition.comment</string> + <key>settings</key> + <dict> + <key>foreground</key> + <string>#08000000</string> + </dict> + </dict> + <dict> + <key>name</key> + <string>Punctuation</string> + <key>scope</key> + <string>punctuation.definition.string, punctuation.definition.variable, punctuation.definition.string, punctuation.definition.parameters, punctuation.definition.string, punctuation.definition.array</string> + <key>settings</key> + <dict> + <key>foreground</key> + <string>#07000000</string> + </dict> + </dict> + <dict> + <key>name</key> + <string>Delimiters</string> + <key>scope</key> + <string>none</string> + <key>settings</key> + <dict> + <key>foreground</key> + <string>#07000000</string> + </dict> + </dict> + <dict> + <key>name</key> + <string>Operators</string> + <key>scope</key> + <string>keyword.operator</string> + <key>settings</key> + <dict> + <key>foreground</key> + <string>#07000000</string> + </dict> + </dict> + <dict> + <key>name</key> + <string>Keywords</string> + <key>scope</key> + <string>keyword</string> + <key>settings</key> + <dict> + <key>foreground</key> + <string>#05000000</string> + </dict> + </dict> + <dict> + <key>name</key> + <string>Variables</string> + <key>scope</key> + <string>variable</string> + <key>settings</key> + <dict> + <key>foreground</key> + <string>#07000000</string> + </dict> + </dict> + <dict> + <key>name</key> + <string>Functions</string> + <key>scope</key> + <string>entity.name.function, meta.require, support.function.any-method</string> + <key>settings</key> + <dict> + <key>foreground</key> + <string>#04000000</string> + </dict> + </dict> + <dict> + <key>name</key> + <string>Labels</string> + <key>scope</key> + <string>entity.name.label</string> + <key>settings</key> + <dict> + <key>foreground</key> + <string>#11000000</string> + </dict> + </dict> + <dict> + <key>name</key> + <string>Classes</string> + <key>scope</key> + <string>support.class, entity.name.class, entity.name.type.class</string> + <key>settings</key> + <dict> + <key>foreground</key> + <string>#03000000</string> + </dict> + </dict> + <dict> + <key>name</key> + <string>Classes</string> + <key>scope</key> + <string>meta.class</string> + <key>settings</key> + <dict> + <key>foreground</key> + <string>#0f000000</string> + </dict> + </dict> + <dict> + <key>name</key> + <string>Methods</string> + <key>scope</key> + <string>keyword.other.special-method</string> + <key>settings</key> + <dict> + <key>foreground</key> + <string>#04000000</string> + </dict> + </dict> + <dict> + <key>name</key> + <string>Storage</string> + <key>scope</key> + <string>storage</string> + <key>settings</key> + <dict> + <key>foreground</key> + <string>#05000000</string> + </dict> + </dict> + <dict> + <key>name</key> + <string>Support</string> + <key>scope</key> + <string>support.function</string> + <key>settings</key> + <dict> + <key>foreground</key> + <string>#06000000</string> + </dict> + </dict> + <dict> + <key>name</key> + <string>Strings, Inherited Class</string> + <key>scope</key> + <string>string, constant.other.symbol, entity.other.inherited-class</string> + <key>settings</key> + <dict> + <key>foreground</key> + <string>#02000000</string> + </dict> + </dict> + <dict> + <key>name</key> + <string>Integers</string> + <key>scope</key> + <string>constant.numeric</string> + <key>settings</key> + <dict> + <key>foreground</key> + <string>#10000000</string> + </dict> + </dict> + <dict> + <key>name</key> + <string>Floats</string> + <key>scope</key> + <string>none</string> + <key>settings</key> + <dict> + <key>foreground</key> + <string>#10000000</string> + </dict> + </dict> + <dict> + <key>name</key> + <string>Boolean</string> + <key>scope</key> + <string>none</string> + <key>settings</key> + <dict> + <key>foreground</key> + <string>#10000000</string> + </dict> + </dict> + <dict> + <key>name</key> + <string>Constants</string> + <key>scope</key> + <string>constant</string> + <key>settings</key> + <dict> + <key>foreground</key> + <string>#10000000</string> + </dict> + </dict> + <dict> + <key>name</key> + <string>Tags</string> + <key>scope</key> + <string>entity.name.tag</string> + <key>settings</key> + <dict> + <key>foreground</key> + <string>#01000000</string> + </dict> + </dict> + <dict> + <key>name</key> + <string>Attributes</string> + <key>scope</key> + <string>entity.other.attribute-name</string> + <key>settings</key> + <dict> + <key>foreground</key> + <string>#10000000</string> + </dict> + </dict> + <dict> + <key>name</key> + <string>Attribute IDs</string> + <key>scope</key> + <string>entity.other.attribute-name.id, punctuation.definition.entity</string> + <key>settings</key> + <dict> + <key>foreground</key> + <string>#04000000</string> + </dict> + </dict> + <dict> + <key>name</key> + <string>Selector</string> + <key>scope</key> + <string>meta.selector</string> + <key>settings</key> + <dict> + <key>foreground</key> + <string>#05000000</string> + </dict> + </dict> + <dict> + <key>name</key> + <string>Values</string> + <key>scope</key> + <string>none</string> + <key>settings</key> + <dict> + <key>foreground</key> + <string>#10000000</string> + </dict> + </dict> + <dict> + <key>name</key> + <string>Headings</string> + <key>scope</key> + <string>markup.heading punctuation.definition.heading, entity.name.section</string> + <key>settings</key> + <dict> + <key>fontStyle</key> + <string></string> + <key>foreground</key> + <string>#04000000</string> + </dict> + </dict> + <dict> + <key>name</key> + <string>Units</string> + <key>scope</key> + <string>keyword.other.unit</string> + <key>settings</key> + <dict> + <key>foreground</key> + <string>#10000000</string> + </dict> + </dict> + <dict> + <key>name</key> + <string>Bold</string> + <key>scope</key> + <string>markup.bold, punctuation.definition.bold</string> + <key>settings</key> + <dict> + <key>fontStyle</key> + <string>bold</string> + <key>foreground</key> + <string>#03000000</string> + </dict> + </dict> + <dict> + <key>name</key> + <string>Italic</string> + <key>scope</key> + <string>markup.italic, punctuation.definition.italic</string> + <key>settings</key> + <dict> + <key>fontStyle</key> + <string>italic</string> + <key>foreground</key> + <string>#05000000</string> + </dict> + </dict> + <dict> + <key>name</key> + <string>Code</string> + <key>scope</key> + <string>markup.raw.inline</string> + <key>settings</key> + <dict> + <key>foreground</key> + <string>#02000000</string> + </dict> + </dict> + <dict> + <key>name</key> + <string>Link Text</string> + <key>scope</key> + <string>string.other.link, punctuation.definition.string.end.markdown, punctuation.definition.string.begin.markdown</string> + <key>settings</key> + <dict> + <key>foreground</key> + <string>#01000000</string> + </dict> + </dict> + <dict> + <key>name</key> + <string>Link Url</string> + <key>scope</key> + <string>meta.link</string> + <key>settings</key> + <dict> + <key>foreground</key> + <string>#10000000</string> + </dict> + </dict> + <dict> + <key>name</key> + <string>Quotes</string> + <key>scope</key> + <string>markup.quote</string> + <key>settings</key> + <dict> + <key>foreground</key> + <string>#10000000</string> + </dict> + </dict> + <dict> + <key>name</key> + <string>Separator</string> + <key>scope</key> + <string>meta.separator</string> + <key>settings</key> + <dict> + <key>background</key> + <string>#13000000</string> + <key>foreground</key> + <string>#07000000</string> + </dict> + </dict> + <dict> + <key>name</key> + <string>Inserted</string> + <key>scope</key> + <string>markup.inserted</string> + <key>settings</key> + <dict> + <key>foreground</key> + <string>#02000000</string> + </dict> + </dict> + <dict> + <key>name</key> + <string>Deleted</string> + <key>scope</key> + <string>markup.deleted</string> + <key>settings</key> + <dict> + <key>foreground</key> + <string>#01000000</string> + </dict> + </dict> + <dict> + <key>name</key> + <string>Changed</string> + <key>scope</key> + <string>markup.changed</string> + <key>settings</key> + <dict> + <key>foreground</key> + <string>#05000000</string> + </dict> + </dict> + <dict> + <key>name</key> + <string>Colors</string> + <key>scope</key> + <string>constant.other.color</string> + <key>settings</key> + <dict> + <key>foreground</key> + <string>#06000000</string> + </dict> + </dict> + <dict> + <key>name</key> + <string>Regular Expressions</string> + <key>scope</key> + <string>string.regexp</string> + <key>settings</key> + <dict> + <key>foreground</key> + <string>#06000000</string> + </dict> + </dict> + <dict> + <key>name</key> + <string>Escape Characters</string> + <key>scope</key> + <string>constant.character.escape</string> + <key>settings</key> + <dict> + <key>foreground</key> + <string>#06000000</string> + </dict> + </dict> + <dict> + <key>name</key> + <string>Embedded</string> + <key>scope</key> + <string>punctuation.section.embedded, variable.interpolation</string> + <key>settings</key> + <dict> + <key>foreground</key> + <string>#05000000</string> + </dict> + </dict> + <dict> + <key>name</key> + <string>Illegal</string> + <key>scope</key> + <string>invalid.illegal</string> + <key>settings</key> + <dict> + <key>background</key> + <string>#01000000</string> + <key>foreground</key> + <string>#0f000000</string> + </dict> + </dict> + <dict> + <key>name</key> + <string>Broken</string> + <key>scope</key> + <string>invalid.broken</string> + <key>settings</key> + <dict> + <key>background</key> + <string>#10000000</string> + <key>foreground</key> + <string>#00000000</string> + </dict> + </dict> + <dict> + <key>name</key> + <string>Deprecated</string> + <key>scope</key> + <string>invalid.deprecated</string> + <key>settings</key> + <dict> + <key>background</key> + <string>#11000000</string> + <key>foreground</key> + <string>#0f000000</string> + </dict> + </dict> + <dict> + <key>name</key> + <string>Unimplemented</string> + <key>scope</key> + <string>invalid.unimplemented</string> + <key>settings</key> + <dict> + <key>background</key> + <string>#08000000</string> + <key>foreground</key> + <string>#0f000000</string> + </dict> + </dict> + </array> + <key>uuid</key> + <string>uuid</string> + </dict> +</plist> diff --git a/assets/themes/base16.tmTheme b/assets/themes/base16.tmTheme index eff2eba4..7b030068 100644 --- a/assets/themes/base16.tmTheme +++ b/assets/themes/base16.tmTheme @@ -3,9 +3,16 @@ <plist version="1.0"> <dict> <!-- + This theme is meant for users who configure their terminal with a base16 + color theme. If you use a 256-color variant along with base16-shell, use + the bat theme base16-256 instead. + + base16: https://github.com/chriskempson/base16 + base16-shell: https://github.com/chriskempson/base16-shell + 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. + palette number from 00 to 0f (the 8 colors and their bright versions), + and AA is the special value 00 to indicate this encoding is being used. --> <key>author</key> <string>Template: Chris Kempson, Scheme: Mitchell Kember</string> diff --git a/src/terminal.rs b/src/terminal.rs index c8e2cd48..b744ba9a 100644 --- a/src/terminal.rs +++ b/src/terminal.rs @@ -8,7 +8,7 @@ pub fn to_ansi_color(color: highlighting::Color, true_color: bool) -> ansi_term: // 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 8-bit color palette number. The built-in themes ansi-light, - // ansi-dark, and base16 use this. + // ansi-dark, base16, and base16-256 use this. 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).