Repository: sharkdp/bat (language: rust)

Issue:
Default theme compatible with light/dark terminals
Hi! 👋
First of all, thanks for making such a great tool!

One reason preventing me from using `bat` much is because there's no theme that's readable on both light and dark terminals. For instance, the default theme shows text as white, which is invisible on a white background.

I think this might be fairly common use case, as macOS' default terminal theme automatically switches between light/dark as the system theme changes.

I wonder if there's any plans of making the default theme compatible with both types of terminals? I think one major improvement would be to show text in the default text color, instead of white.

I'd be happy to help if this would seem reasonable.


Discussion / hints:
https://github.com/sharkdp/bat#dark-mode
That’s good to know, thanks! It’ll only work on macOS however, and I’m sure people like to use `bat` in a variety of environments.
I recently moved to Linux ([Pop OS](https://pop.system76.com/), i.e. Gnome with [Pop Shell](https://github.com/pop-os/shell)) from macOS and I am switching between dark mode and light mode. Bat stands out as a program I use constantly that doesn't play well with my light mode daytime theme.
How do other programs detect dark mode? Does your terminal style change? Do other terminal programs react to the change?
In Gnome Terminal, in my profile -> Colors -> Text and Background Color, I checked "Use colors from system theme", which makes it respect Dark Mode. The terminal background and text colors change as the system theme changes between light and dark themes.

Web pages in web browsers use [the prefers-color-scheme media query](https://web.dev/prefers-color-scheme/) but I'm not sure if that's relevant here.
> In Gnome Terminal, in my profile -> Colors -> Text and Background Color, I checked "Use colors from system theme", which makes it respect Dark Mode. The terminal background and text colors change as the system theme changes between light and dark themes.

If the terminal theme changes, you could use `bat`s `base16` theme (which changes with the terminal theme). It's not ideal though, as the color choice is severely limited.

A better choice would be to automatically select a pre-configured dark/light theme (like Monokai vs. GitHub). But this would require us to somehow get a hold of that Gnome property.
Here's an interesting thread on detecting the terminal background color: https://unix.stackexchange.com/questions/245378/common-environment-variable-to-set-dark-or-light-terminal-background

I'm not knowledgeable enough to know if this is useful info.
The easiest way support both light and dark themes is to use the standard ANSI colors, default text color for text (i.e. not explicitly specify white or black), and no background color.
> The easiest way support both light and dark themes is to use the standard ANSI colors, default text color for text (i.e. not explicitly specify white or black), and no background color.

Maybe. But it's also a way that restricts the color output to 256 colors. Something that I simply refuse to fall back to (as a standard / by default) in 2020. 

I didn't do any extensive research, but I guess there could be a way to query the current theme with something like
```
gsettings get org.gnome.desktop.interface gtk-theme
```
Meanwhile, here's an alternative that displays nicely on any old light/dark ANSI terminal:

```shell
wat() { 
    if [ -t 1 ]; then
        highlight --force --stdout -O ansi "$@" | less -RFX
    else
        cat "$@"
    fi
}
```

Requires `brew install highlight` or whatever your package manager is.
> I didn't do any extensive research, but I guess there could be a way to query the current theme with something like
> 
> ```
> gsettings get org.gnome.desktop.interface gtk-theme
> ```

That appears to work for me, the light theme is 'Pop' and the dark theme is 'Pop-dark'. Now what do we do with that info? :)

> > ```
> > gsettings get org.gnome.desktop.interface gtk-theme
> > ```
> 
> That appears to work for me, the light theme is 'Pop' and the dark theme is 'Pop-dark'. Now what do we do with that info? :)

A wrapper command could work:

```bash
bat() {
    local sys_theme="$(gsettings get org.gnome.desktop.interface gtk-theme)"
    local bat_theme
    case "${sys_theme}" in
    "Pop") bat_theme="GitHub" ;;
    "Pop-dark") bat_theme="default" ;;
    *) bat_theme="default" ;;
    esac
    command bat --theme="${bat_theme}"
}
```

If you add that to your bash profile, it should work just by using the bat command as usual.
> But it's also a way that restricts the color output to 256 colors.

This is a good thing. It means that you have consistent colors throughout your terminal usage, instead of each CLI utility using its own themes with clashing colors; and when you want to change theme you can do so in one location instead of having to recustomise every single utility.

I've given up on having utilities that work correctly across light and dark backgrounds and have reconfigured my light themes so that white -> black and black -> white, but defaulting to `ansi-dark` would at least get you most of the way there to supporting users custom terminal themes without configuration.
> This is a good thing. It means that you have consistent colors throughout your terminal usage, instead of each CLI utility using its own themes with clashing colors

You can still have widely different themes with 256 colors. Maybe what you meant are the base 16 colors that are usually customized to a certain theme? (the 256 colors can also be customized, but usually are not).

> but defaulting to ansi-dark would at least get you most of the way there to supporting users custom terminal themes without configuration

The problem with the base16 (and even the 256 color) themes is that I find that really limiting. I'm old enough to remember the times when I was able to switch Windows from 256 to "true color". And I do not want to go back there. Using 24bit colors should be a standard.

In any case, `bat` leaves the choice to the user. It's also really easy to change a theme.
Closing this for now, as I don't see what we could do inside `bat`.
If anyone's curious, here's what I did with [fish shell](https://fishshell.com/) in [Gnome Terminal](https://en.wikipedia.org/wiki/GNOME_Terminal). I wrote a function I called `theme_bat`:
```fish
function theme_bat
    switch (gsettings get org.gnome.desktop.interface gtk-theme)
    case "'Pop'"
        set -gx BAT_THEME GitHub
    case "'Pop-dark'"
        set -gx BAT_THEME default
    case '*'
        echo "I don't recognize the GTK theme"
    end
end
```
Then in Gnome Terminal, I went to Preferences -> Profiles -> MyThemeName -> Command, checked "Run a custom command instead of my shell" and for my custom command I entered `/usr/bin/fish -c 'theme_bat';/usr/bin/fish`.

This means when I open Gnome Terminal in my default theme, it first runs a script that checks whether the GTK theme is light or dark, then sets the $BAT_THEME shell variable to the appropriate theme. Then it runs my regular shell.

Note that this doesn't affect other terminal emulators such as Alacritty (which doesn't currently integrate with the GTK light/dark mode), they can continue with the default bat theme or whatever configuration is best for them.
## Alternative 1: Gnome Night Mode + Shell alias

1. Create a shell script (i.e. `~/.local/bin/is_night`):
```sh
#!/usr/bin/env bash

# This relies on the user defined time window within Gnome Night Mode settings.
NOW=$(date +'%H.0')
NIGHT_TIME_START=$(gsettings get org.gnome.settings-daemon.plugins.color night-light-schedule-from)
NIGHT_TIME_END=$(gsettings get org.gnome.settings-daemon.plugins.color night-light-schedule-to)

# d=day n=night
function isNight()
{
  if [ $(echo "${NIGHT_TIME_START} < ${NIGHT_TIME_END}" | bc -q) == 1 ]
  then
    # pattern: dnd
    OP='-a'
  else 
    # pattern: ndn
    OP='-o'
  fi

  [ $(echo "${NOW} > ${NIGHT_TIME_START}" | bc -q) == 1  "$OP"  $(echo "${NOW} < ${NIGHT_TIME_END}" | bc -q) == 1 ]
}

isNight
```

Make sure `~/.local/bin` is part of your `$PATH` and the script is executable. Then adjust the suggested shell alias as follows:
```sh
alias cat="bat --theme=\$(is_night && echo myNightTheme || echo myDayTheme)"
```

## Alternative 2: Use Gnome Extension and modify bat's config file
Here is another, maybe more consistent way, to handle the switch, that is based on the [Night Theme Switcher](https://extensions.gnome.org/extension/2236/night-theme-switcher/) extension for the Gnome Shell.

Create the script `night_mode`, mark it executable and a link to it called `day_mode`:
```sh
#!/usr/bin/env bash

update_bat()
{
  CONFIG_FILE_PATH="$(bat --config-file)"
  THEME="${1/day/GitHub}"
  THEME="${THEME/night/1337}"
  
  if [ ! -f "$CONFIG_FILE_PATH" ]
  then
    bat --generate-config-file
    if [ ! -f "$CONFIG_FILE_PATH" ]
    then
      echo "Could neither find nor create config file \"$CONFIG_FILE_PATH\""
      exit 1
    fi
  fi
  
  # switch bat
  sed --in-place "s/^--theme=.*$/--theme=$THEME/"  "$CONFIG_FILE_PATH"
}

SCRIPT_NAME=$(basename $0)
MODE=${SCRIPT_NAME/%_mode/} 

echo "Switching to $MODE mode"
update_bat $MODE
```

Then configure the scripts to be executed by the Night Switch Shell Extension on night/day switch respectively.

Thanks for all the workarounds!

I still think `bat` should be able to provide a theme that only uses ANSI colors, so that (1) it automatically works with light and dark terminals without hacks, and (2) works consistently on any ANSI terminal (even in a vanilla `tmux`) without the dependency on special terminal capabilities (e.g. 256 colors), which often aren't the default. This is how most UNIX tools with colors work.
@hoffa Isn't that covered by one of the `base16` themes? See https://github.com/sharkdp/bat#8-bit-themes
@sharkdp It's very close! The only problem I see is that they use a hardcoded color for normal text (i.e. explicitly specifying text as black or white), instead of using the terminal default (`\033[0m`). This means `ansi-dark` and `base16` aren't really legible on a light terminal, and `ansi-light` isn't really legible on a dark terminal.
For that purpose you can use any of the examples above to switch the theme from ansi-dark to ansi-light and the other way around. I do the same with a script using sed ... you could also create two config files for both dark and light versions and a symbolic link to one of those files depending on the daytime. Good enough for me.
@hoffa I see, thank you for the information. @mk12 FYI - If you are interested. Do you think we could somehow achieve that for the `base16` themes? I guess it would require special handling in `bat` itself, not just the theme.
> This is a good thing. It means that you have consistent colors throughout your terminal usage, instead of each CLI utility using its own themes with clashing colors; and when you want to change theme you can do so in one location instead of having to recustomise every single utility.

I'm sympathetic to this view. I want my terminal to be a controlled environment, not like a web browser. I configure the terminal's font in one place, not in every CLI app's config, and I expect it to be the same with color palettes. It's a tradeoff, but I think 16 colors is more than enough for syntax highlighting. (There are cases where it really does feel limiting, e.g. for [delta](https://github.com/dandavison/delta) to overlay syntax & diff highlighting your palette would also need "muted red bg", "muted green bg", etc.)

> @mk12 FYI - If you are interested. Do you think we could somehow achieve that for the base16 themes? I guess it would require special handling in bat itself, not just the theme.

I propose deprecating `ansi-light` and `ansi-dark`, replacing them with a single `ansi` theme that works for both. All it needs to do is use default fg/bg instead of white/black. I'll give it a shot now.

Fix patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 9c866a5f21..36337ffaa3 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -11,6 +11,8 @@
 
 ## New themes
 
+- `ansi` replaces `ansi-dark` and `ansi-light`, see #1104 and #1412 (@mk12)
+
 ## `bat` as a library
 
 ## Packaging
diff --git a/README.md b/README.md
index f3ab11088d..4204a13190 100644
--- a/README.md
+++ b/README.md
@@ -381,12 +381,11 @@ You can also use a custom theme by following the
 
 ### 8-bit themes
 
-`bat` has four themes that always use [8-bit colors](https://en.wikipedia.org/wiki/ANSI_escape_code#Colors),
+`bat` has three 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.
+- `ansi` looks decent on any terminal. It uses 3-bit colors: black, red, green,
+  yellow, blue, magenta, cyan, and white.
 - `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).
diff --git a/assets/themes.bin b/assets/themes.bin
index bc291724f6..78906ba326 100644
Binary files a/assets/themes.bin and b/assets/themes.bin differ
diff --git a/assets/themes/ansi-light.tmTheme b/assets/themes/ansi-light.tmTheme
deleted file mode 100644
index 5dfb94e829..0000000000
--- a/assets/themes/ansi-light.tmTheme
+++ /dev/null
@@ -1,504 +0,0 @@
-<?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>
-        <!--
-        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>
-        <string>Template: Chris Kempson, Scheme: Mitchell Kember</string>
-        <key>name</key>
-        <string>ANSI Light</string>
-        <key>colorSpaceName</key>
-        <string>sRGB</string>
-        <key>settings</key>
-        <array>
-            <dict>
-                <key>settings</key>
-                <dict>
-                    <key>background</key>
-                    <string>#07000000</string>
-                    <key>caret</key>
-                    <string>#00000000</string>
-                    <key>foreground</key>
-                    <string>#00000000</string>
-                    <key>invisibles</key>
-                    <string>#00000000</string>
-                    <key>lineHighlight</key>
-                    <string>#00000000</string>
-                    <key>selection</key>
-                    <string>#00000000</string>
-                    <key>gutter</key>
-                    <string>#07000000</string>
-                    <key>gutterForeground</key>
-                    <string>#00000000</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>#00000000</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>#02000000</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>#00000000</string>
-                </dict>
-            </dict>
-            <dict>
-                <key>name</key>
-                <string>Delimiters</string>
-                <key>scope</key>
-                <string>none</string>
-                <key>settings</key>
-                <dict>
-                    <key>foreground</key>
-                    <string>#00000000</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>#00000000</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>#00000000</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>#06000000</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>#00000000</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>#03000000</string>
-                </dict>
-            </dict>
-            <dict>
-                <key>name</key>
-                <string>Floats</string>
-                <key>scope</key>
-                <string>none</string>
-                <key>settings</key>
-                <dict>
-                    <key>foreground</key>
-                    <string>#03000000</string>
-                </dict>
-            </dict>
-            <dict>
-                <key>name</key>
-                <string>Boolean</string>
-                <key>scope</key>
-                <string>none</string>
-                <key>settings</key>
-                <dict>
-                    <key>foreground</key>
-                    <string>#03000000</string>
-                </dict>
-            </dict>
-            <dict>
-                <key>name</key>
-                <string>Constants</string>
-                <key>scope</key>
-                <string>constant</string>
-                <key>settings</key>
-                <dict>
-                    <key>foreground</key>
-                    <string>#03000000</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>#03000000</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>#03000000</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>#03000000</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>#03000000</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>#03000000</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>#00000000</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>#03000000</string>
-                    <key>foreground</key>
-                    <string>#07000000</string>
-                </dict>
-            </dict>
-        </array>
-        <key>uuid</key>
-        <string>uuid</string>
-    </dict>
-</plist>
diff --git a/assets/themes/ansi-dark.tmTheme b/assets/themes/ansi.tmTheme
similarity index 81%
rename from assets/themes/ansi-dark.tmTheme
rename to assets/themes/ansi.tmTheme
index a797695143..957f42bba6 100644
--- a/assets/themes/ansi-dark.tmTheme
+++ b/assets/themes/ansi.tmTheme
@@ -3,14 +3,14 @@
 <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
-        that this encoding is being used.
+        The colors in this theme are encoded as #RRGGBBAA where:
+        * If AA is 00, then RR is an ANSI palette number from 00 to 07.
+        * If AA is 01, the terminal's default fg/bg color is used.
         -->
         <key>author</key>
         <string>Template: Chris Kempson, Scheme: Mitchell Kember</string>
         <key>name</key>
-        <string>ANSI Dark</string>
+        <string>ANSI</string>
         <key>colorSpaceName</key>
         <string>sRGB</string>
         <key>settings</key>
@@ -19,32 +19,17 @@
                 <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>#07000000</string>
-                    <key>lineHighlight</key>
-                    <string>#07000000</string>
-                    <key>selection</key>
-                    <string>#07000000</string>
+                    <string>#00000001</string>
+                    <key>foreground</key>
+                    <string>#00000001</string>
+                    <!--
+                    Explicitly set the gutter color since bat falls back to a
+                    hardcoded DEFAULT_GUTTER_COLOR otherwise.
+                    -->
                     <key>gutter</key>
-                    <string>#00000000</string>
+                    <string>#00000001</string>
                     <key>gutterForeground</key>
-                    <string>#07000000</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>
+                    <string>#00000001</string>
                 </dict>
             </dict>
             <dict>
@@ -58,39 +43,6 @@
                     <string>#02000000</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>
@@ -102,17 +54,6 @@
                     <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>
@@ -146,17 +87,6 @@
                     <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>#07000000</string>
-                </dict>
-            </dict>
             <dict>
                 <key>name</key>
                 <string>Methods</string>
@@ -480,8 +410,6 @@
                 <dict>
                     <key>background</key>
                     <string>#01000000</string>
-                    <key>foreground</key>
-                    <string>#07000000</string>
                 </dict>
             </dict>
             <dict>
@@ -493,8 +421,6 @@
                 <dict>
                     <key>background</key>
                     <string>#03000000</string>
-                    <key>foreground</key>
-                    <string>#00000000</string>
                 </dict>
             </dict>
         </array>
diff --git a/src/assets.rs b/src/assets.rs
index eecb069374..734c6d20fd 100644
--- a/src/assets.rs
+++ b/src/assets.rs
@@ -189,6 +189,15 @@ impl HighlightingAssets {
         match self.theme_set.themes.get(theme) {
             Some(theme) => theme,
             None => {
+                if theme == "ansi-light" || theme == "ansi-dark" {
+                    use ansi_term::Colour::Yellow;
+                    eprintln!(
+                        "{}: Theme '{}' is deprecated, using 'ansi' instead.",
+                        Yellow.paint("[bat warning]"),
+                        theme
+                    );
+                    return self.get_theme("ansi");
+                }
                 if theme != "" {
                     use ansi_term::Colour::Yellow;
                     eprintln!(
diff --git a/src/printer.rs b/src/printer.rs
index ba74872a5c..6558fe10c1 100644
--- a/src/printer.rs
+++ b/src/printer.rs
@@ -451,7 +451,7 @@ impl<'a> Printer for InteractivePrinter<'a> {
                 if text.len() != text_trimmed.len() {
                     if let Some(background_color) = background_color {
                         let mut ansi_style = Style::default();
-                        ansi_style.background = Some(to_ansi_color(background_color, true_color));
+                        ansi_style.background = to_ansi_color(background_color, true_color);
                         let width = if cursor_total <= cursor_max {
                             cursor_max - cursor_total + 1
                         } else {
@@ -592,8 +592,7 @@ impl<'a> Printer for InteractivePrinter<'a> {
 
             if let Some(background_color) = background_color {
                 let mut ansi_style = Style::default();
-                ansi_style.background =
-                    Some(to_ansi_color(background_color, self.config.true_color));
+                ansi_style.background = to_ansi_color(background_color, self.config.true_color);
 
                 write!(
                     handle,
@@ -627,20 +626,27 @@ impl Colors {
     }
 
     fn colored(theme: &Theme, true_color: bool) -> Self {
-        let gutter_color = theme
-            .settings
-            .gutter_foreground
-            .map(|c| to_ansi_color(c, true_color))
-            .unwrap_or(Fixed(DEFAULT_GUTTER_COLOR));
+        let gutter_style = Style {
+            foreground: match theme.settings.gutter_foreground {
+                // If the theme provides a gutter foreground color, use it.
+                // Note: It might be the special value #00000001, in which case
+                // to_ansi_color returns None and we use an empty Style
+                // (resulting in the terminal's default foreground color).
+                Some(c) => to_ansi_color(c, true_color),
+                // Otherwise, use a specific fallback color.
+                None => Some(Fixed(DEFAULT_GUTTER_COLOR)),
+            },
+            ..Style::default()
+        };
 
         Colors {
-            grid: gutter_color.normal(),
-            rule: gutter_color.normal(),
+            grid: gutter_style,
+            rule: gutter_style,
             filename: Style::new().bold(),
             git_added: Green.normal(),
             git_removed: Red.normal(),
             git_modified: Yellow.normal(),
-            line_number: gutter_color.normal(),
+            line_number: gutter_style,
         }
     }
 }
diff --git a/src/terminal.rs b/src/terminal.rs
index b744ba9ac2..b71593470d 100644
--- a/src/terminal.rs
+++ b/src/terminal.rs
@@ -3,13 +3,13 @@ use ansi_term::{self, Style};
 
 use syntect::highlighting::{self, FontStyle};
 
-pub fn to_ansi_color(color: highlighting::Color, true_color: bool) -> ansi_term::Color {
+pub fn to_ansi_color(color: highlighting::Color, true_color: bool) -> Option<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 8-bit color palette number. The built-in themes ansi-light,
-        // ansi-dark, base16, and base16-256 use this.
-        match color.r {
+        // to the 8-bit color palette number. The built-in themes ansi, base16,
+        // and base16-256 use this.
+        Some(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
@@ -31,11 +31,18 @@ pub fn to_ansi_color(color: highlighting::Color, true_color: bool) -> ansi_term:
             // 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 color.a == 1 {
+        // Themes can specify the terminal's default foreground/background color
+        // (i.e. no escape sequence) using the encoding #RRGGBBAA with AA set to
+        // 01. The built-in theme ansi uses this.
+        None
     } else if true_color {
-        RGB(color.r, color.g, color.b)
+        Some(RGB(color.r, color.g, color.b))
     } else {
-        Fixed(ansi_colours::ansi256_from_rgb((color.r, color.g, color.b)))
+        Some(Fixed(ansi_colours::ansi256_from_rgb((
+            color.r, color.g, color.b,
+        ))))
     }
 }
 
@@ -54,7 +61,10 @@ pub fn as_terminal_escaped(
     let mut style = if !colored {
         Style::default()
     } else {
-        let mut color = Style::from(to_ansi_color(style.foreground, true_color));
+        let mut color = Style {
+            foreground: to_ansi_color(style.foreground, true_color),
+            ..Style::default()
+        };
         if style.font_style.contains(FontStyle::BOLD) {
             color = color.bold();
         }
@@ -67,6 +77,6 @@ pub fn as_terminal_escaped(
         color
     };
 
-    style.background = background_color.map(|c| to_ansi_color(c, true_color));
+    style.background = background_color.and_then(|c| to_ansi_color(c, true_color));
     style.paint(text).to_string()
 }


Test patch:
diff --git a/tests/assets.rs b/tests/assets.rs
index 55b5399e59..435ddf855b 100644
--- a/tests/assets.rs
+++ b/tests/assets.rs
@@ -30,8 +30,7 @@ fn all_themes_are_present() {
             "Solarized (light)",
             "Sublime Snazzy",
             "TwoDark",
-            "ansi-dark",
-            "ansi-light",
+            "ansi",
             "base16",
             "base16-256",
             "gruvbox",