Skip to content

style background color ignored #3551

@peteryland

Description

@peteryland

What steps will reproduce the bug?

  1. use a theme with a style that includes a background color
  2. bat a file which uses this style
  3. observe that the background color is not honored

e.g.

mkdir -p .config/bat/themes && \
echo '<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
  <dict>
    <key>settings</key>
    <array>
      <dict>
        <key>settings</key>
        <dict>
          <key>background</key>
          <string>#01000000</string>
          <key>foreground</key>
          <string>#02000000</string>
        </dict>
      </dict>
      <dict>
        <key>name</key>
        <string>Comment</string>
        <key>scope</key>
        <string>comment</string>
        <key>settings</key>
        <dict>
          <key>foreground</key>
          <string>#02000000</string>
          <key>background</key>
          <string>#03000000</string>
          <key>fontStyle</key>
          <string>italic</string>
        </dict>
      </dict>
    </array>
  </dict>
</plist>' > .config/bat/themes/repro.tmTheme && \
batcat cache --build && \
batcat --language=Python --theme=repro --italic-text=always --style=plain --color=always <<< 'def f(x): x # comment' | xxd

What happens?

The specified background color is not presented.

For the example above, the output is:

00000000: 1b5b 3332 6d64 6566 1b5b 306d 1b5b 3332  .[32mdef.[0m.[32
00000010: 6d20 1b5b 306d 1b5b 3332 6d66 1b5b 306d  m .[0m.[32mf.[0m
00000020: 1b5b 3332 6d28 1b5b 306d 1b5b 3332 6d78  .[32m(.[0m.[32mx
00000030: 1b5b 306d 1b5b 3332 6d29 1b5b 306d 1b5b  .[0m.[32m).[0m.[
00000040: 3332 6d3a 1b5b 306d 1b5b 3332 6d20 1b5b  32m:.[0m.[32m .[
00000050: 306d 1b5b 3332 6d78 1b5b 306d 1b5b 3332  0m.[32mx.[0m.[32
00000060: 6d20 1b5b 306d 1b5b 333b 3332 6d23 1b5b  m .[0m.[3;32m#.[
00000070: 306d 1b5b 333b 3332 6d20 636f 6d6d 656e  0m.[3;32m commen
00000080: 741b 5b30 6d0a                           t.[0m.

What did you expect to happen instead?

Text should be printed with the specified background color.

In the xxd output, I would expect to see escape codes that set the background color.

How did you install bat?

apt on Debian forky as of 2026-01-09

Relevant code

I don't know Rust, but I presume that the code around https://github.com/sharkdp/bat/blob/master/src/terminal.rs#L65 is not using the background from the fetched style, and in any case overriding it with a None (or Some of the highlight background) in line 80 anyway.

bat version and environment

$ lsb_release -a
No LSB modules are available.
Distributor ID:	Debian
Description:	Debian GNU/Linux forky/sid
Release:	n/a
Codename:	forky
$ batcat --version
bat 0.25.0
$ batcat --diagnostic 
bat has been built without the 'bugreport' feature. The '--diagnostic' option is not available.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions