From f9d5e81f0e72a130ccbe466c82ee1a0acb919c3d Mon Sep 17 00:00:00 2001 From: Mitchell Kember Date: Sun, 19 Jul 2020 16:49:10 -0400 Subject: [PATCH] Add new theme: base16-256 Bat already has a base16 theme. The new base16-256 theme is for users of base16-shell, who configure their terminal with a 256-color variant of a base16 theme. These variants put some of the base16 colors in elsewhere in the 256-color table to avoid clobbering bright color slots (ansi codes 8 to 15) with colors that don't respect the ordinary meaning of that slot (e.g. bright green in ordinary base16 is not green). For more details, see https://github.com/chriskempson/base16-shell --- CHANGELOG.md | 1 + README.md | 27 +- assets/themes/base16-256.tmTheme | 551 +++++++++++++++++++++++++++++++ assets/themes/base16.tmTheme | 11 +- src/terminal.rs | 2 +- 5 files changed, 586 insertions(+), 6 deletions(-) create mode 100644 assets/themes/base16-256.tmTheme 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 @@ + + + + + + author + Template: Chris Kempson, Scheme: Mitchell Kember + name + Base16 256 + colorSpaceName + sRGB + settings + + + settings + + background + #00000000 + caret + #07000000 + foreground + #07000000 + invisibles + #08000000 + lineHighlight + #08000000 + selection + #13000000 + gutter + #12000000 + gutterForeground + #08000000 + + + + name + Text + scope + variable.parameter.function + settings + + foreground + #07000000 + + + + name + Comments + scope + comment, punctuation.definition.comment + settings + + foreground + #08000000 + + + + name + Punctuation + scope + punctuation.definition.string, punctuation.definition.variable, punctuation.definition.string, punctuation.definition.parameters, punctuation.definition.string, punctuation.definition.array + settings + + foreground + #07000000 + + + + name + Delimiters + scope + none + settings + + foreground + #07000000 + + + + name + Operators + scope + keyword.operator + settings + + foreground + #07000000 + + + + name + Keywords + scope + keyword + settings + + foreground + #05000000 + + + + name + Variables + scope + variable + settings + + foreground + #07000000 + + + + name + Functions + scope + entity.name.function, meta.require, support.function.any-method + settings + + foreground + #04000000 + + + + name + Labels + scope + entity.name.label + settings + + foreground + #11000000 + + + + name + Classes + scope + support.class, entity.name.class, entity.name.type.class + settings + + foreground + #03000000 + + + + name + Classes + scope + meta.class + settings + + foreground + #0f000000 + + + + name + Methods + scope + keyword.other.special-method + settings + + foreground + #04000000 + + + + name + Storage + scope + storage + settings + + foreground + #05000000 + + + + name + Support + scope + support.function + settings + + foreground + #06000000 + + + + name + Strings, Inherited Class + scope + string, constant.other.symbol, entity.other.inherited-class + settings + + foreground + #02000000 + + + + name + Integers + scope + constant.numeric + settings + + foreground + #10000000 + + + + name + Floats + scope + none + settings + + foreground + #10000000 + + + + name + Boolean + scope + none + settings + + foreground + #10000000 + + + + name + Constants + scope + constant + settings + + foreground + #10000000 + + + + name + Tags + scope + entity.name.tag + settings + + foreground + #01000000 + + + + name + Attributes + scope + entity.other.attribute-name + settings + + foreground + #10000000 + + + + name + Attribute IDs + scope + entity.other.attribute-name.id, punctuation.definition.entity + settings + + foreground + #04000000 + + + + name + Selector + scope + meta.selector + settings + + foreground + #05000000 + + + + name + Values + scope + none + settings + + foreground + #10000000 + + + + name + Headings + scope + markup.heading punctuation.definition.heading, entity.name.section + settings + + fontStyle + + foreground + #04000000 + + + + name + Units + scope + keyword.other.unit + settings + + foreground + #10000000 + + + + name + Bold + scope + markup.bold, punctuation.definition.bold + settings + + fontStyle + bold + foreground + #03000000 + + + + name + Italic + scope + markup.italic, punctuation.definition.italic + settings + + fontStyle + italic + foreground + #05000000 + + + + name + Code + scope + markup.raw.inline + settings + + foreground + #02000000 + + + + name + Link Text + scope + string.other.link, punctuation.definition.string.end.markdown, punctuation.definition.string.begin.markdown + settings + + foreground + #01000000 + + + + name + Link Url + scope + meta.link + settings + + foreground + #10000000 + + + + name + Quotes + scope + markup.quote + settings + + foreground + #10000000 + + + + name + Separator + scope + meta.separator + settings + + background + #13000000 + foreground + #07000000 + + + + name + Inserted + scope + markup.inserted + settings + + foreground + #02000000 + + + + name + Deleted + scope + markup.deleted + settings + + foreground + #01000000 + + + + name + Changed + scope + markup.changed + settings + + foreground + #05000000 + + + + name + Colors + scope + constant.other.color + settings + + foreground + #06000000 + + + + name + Regular Expressions + scope + string.regexp + settings + + foreground + #06000000 + + + + name + Escape Characters + scope + constant.character.escape + settings + + foreground + #06000000 + + + + name + Embedded + scope + punctuation.section.embedded, variable.interpolation + settings + + foreground + #05000000 + + + + name + Illegal + scope + invalid.illegal + settings + + background + #01000000 + foreground + #0f000000 + + + + name + Broken + scope + invalid.broken + settings + + background + #10000000 + foreground + #00000000 + + + + name + Deprecated + scope + invalid.deprecated + settings + + background + #11000000 + foreground + #0f000000 + + + + name + Unimplemented + scope + invalid.unimplemented + settings + + background + #08000000 + foreground + #0f000000 + + + + uuid + uuid + + 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 @@ author Template: Chris Kempson, Scheme: Mitchell Kember 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).