Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Theme based on terminal colors doesn't work on Tmux #3207

Open
YaFou opened this issue Feb 10, 2025 · 7 comments
Open

Theme based on terminal colors doesn't work on Tmux #3207

YaFou opened this issue Feb 10, 2025 · 7 comments
Labels
bug Something isn't working

Comments

@YaFou
Copy link

YaFou commented Feb 10, 2025

What steps will reproduce the bug?

  1. Use the following configuration:
--theme-dark="[dark theme]"
--theme-light="[light theme]"

(I use Catppuccin)

  1. Launch a Tmux session
  2. Run bat file. The theme should be the correct one.
  3. Change your terminal theme.
  4. Run once again bat file. The theme should be wrong.

What happens?
The theme doesn't switch properly.

What did you expect to happen instead?
The theme should switch when I switch to dark or light mode.

How did you install bat?

Using the Arch package repository


bat version and environment

Software version

bat 0.25.0 (v0.25.0-modified)

Operating system

Linux 6.12.10-arch1-1

Command-line

bat .zshrc --diagnostic

Environment variables

BAT_CACHE_PATH=<not set>
BAT_CONFIG_PATH=<not set>
BAT_OPTS=<not set>
BAT_PAGER=<not set>
BAT_PAGING=<not set>
BAT_STYLE=<not set>
BAT_TABS=<not set>
BAT_THEME=<not set>
COLORTERM=truecolor
LANG=fr_FR.UTF-8
LC_ALL=<not set>
LESS=<not set>
MANPAGER='sh -c '\''col -bx | bat -l man -p'\'''
NO_COLOR=<not set>
PAGER=<not set>
SHELL=/usr/bin/zsh
TERM=tmux-256color
XDG_CACHE_HOME=<not set>
XDG_CONFIG_HOME=<not set>

System Config file

Could not read contents of '/etc/bat/config': No such file or directory (os error 2).

Config file

--theme-dark="Catppuccin Mocha"
--theme-light="Catppuccin Latte"

Custom assets metadata

bat_version: 0.25.0
creation_time:
  secs_since_epoch: 1737367908
  nanos_since_epoch: 307702877

Custom assets

  • metadata.yaml, 97 bytes
  • syntaxes.bin, 969578 bytes
  • themes.bin, 49134 bytes

Compile time information

  • Profile: release
  • Target triple: x86_64-unknown-linux-gnu
  • Family: unix
  • OS: linux
  • Architecture: x86_64
  • Pointer width: 64
  • Endian: little
  • CPU features: fxsr,sse,sse2
  • Host: x86_64-unknown-linux-gnu

Less version

> less --version
less 668 (PCRE2 regular expressions)
Copyright (C) 1984-2024  Mark Nudelman

less comes with NO WARRANTY, to the extent permitted by law.
For information about the terms of redistribution,
see the file named README in the less distribution.
Home page: https://greenwoodsoftware.com/less
@YaFou YaFou added the bug Something isn't working label Feb 10, 2025
@keith-hall
Copy link
Collaborator

If you want the colors to change after bat has already passed it's output to the pager, I guess we would need a built-in pager like mentioned at #1053

@YaFou
Copy link
Author

YaFou commented Feb 10, 2025

If you want the colors to change after bat has already passed it's output to the pager, I guess we would need a built-in pager like mentioned at #1053

I should have been more precise. I have updated the steps to reproduce the bug.

@eth-p
Copy link
Collaborator

eth-p commented Feb 10, 2025

What tmux version are you using, and do you have any pane styles set?

If I recall correctly, the older versions didn't support background color querying at all, while the newer tmux versions respond directly to the query instead of going through the terminal.

@YaFou
Copy link
Author

YaFou commented Feb 12, 2025

What tmux version are you using, and do you have any pane styles set?

If I recall correctly, the older versions didn't support background color querying at all, while the newer tmux versions respond directly to the query instead of going through the terminal.

My Tmux version is 3.5a.

My theme is:

source-file ~/.local/share/tmux/theme.conf
set -g default-terminal "tmux-256color"

# Status
set -g status-left ""
set -g status-right "#[fg=#{@theme_mauve}]◖#[fg=#{@theme_base},bg=#{@theme_mauve}] #[fg=#{@theme_text},bg=#{@theme_surface_0}] #S#[fg=#{@theme_surface_0},bg=#{@theme_base}]◗"
set -g status-style "bg=#{@theme_base},fg=#{@theme_text}"

# Window
set -g window-status-format "#[fg=#{@theme_rosewater}]◖#[fg=#{@theme_base},bg=#{@theme_rosewater}]#I #[fg=#{@theme_text},bg=#{@theme_surface_0}] #W#[fg=#{@theme_surface_0},bg=#{@theme_base}]◗"
set -g window-status-current-format "#[fg=#{@theme_green}]◖#[fg=#{@theme_base},bg=#{@theme_green}]#I #[fg=#{@theme_text},bg=#{@theme_surface_0}] #W#[fg=#{@theme_surface_0},bg=#{@theme_base}]◗"

# Message
set -g message-style "fg=#{@theme_text},bg=#{@theme_surface_0}"
set -g message-command-style "fg=#{@theme_text},bg=#{@theme_surface_2}"

# Menu
set -g menu-selected-style "bg=#{@theme_green},fg=#{@theme_base}"
set -g menu-style "bg=#{@theme_green},fg=#{@theme_base}"

where ~/.local/share/tmux/theme.conf is updated according to the system theme. I'm using catppuccin-latte et catppuccin-mocha from this repo.

@shanscendent
Copy link

I can reproduce this problem as well, on the same bat 0.25.0 (with no configuration), and tmux 3.5a (with oh-my-tmux config) installed with homebrew on macOS 15.3.

bat works fine in my terminal (ghostty), but is stuck on the active theme (light or dark) when the tmux session is launched.

@YaFou
Copy link
Author

YaFou commented Feb 13, 2025

This might be related to this issue.

@eth-p
Copy link
Collaborator

eth-p commented Feb 14, 2025

I was able to reproduce the behavior, and the upstream tmux issue you mentioned appears to be the underlying cause. Using tmux 3.5a, it will return the original terminal background color when queried, but only until I resize the terminal window. As the linked issue describes, the fix they implemented works by invalidating the cached color when a SIGWINCH signal is sent by the terminal. Unfortunately, it seems that not all of the terminal emulators will do that when the background color is changed, though.

Ideally, one of two things would fix this:

  • tmux adds another way to invalidate the cached background color; or
  • more terminal emulators are updated to send SIGWINCH when the background color is changed.

Another option would be to make a pull request for terminal-colorsaurus to handle tmux as a special case. If the TMUX environment variable is set, the OSC 11 query could use the tmux passthrough escape sequence to query the terminal directly. This comes with the downside that it would no longer detect the right background color when tmux has the window-style bg=#...... option set, though.

In the meantime, I can think of a couple of workarounds that can be used until a better solution is implemented:

  • Resize the terminal window to force tmux to re-check the background color.
  • Detach and reattach to the tmux session.
  • Figure out a way to also run tmux set-option window-style bg=#rrggbb when you change the terminal background color.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants