dalance / termbg

A Rust library for terminal background color detection
Apache License 2.0
80 stars 5 forks source link

Tmux does not appear to work #20

Open aykevl opened 1 year ago

aykevl commented 1 year ago

Tmux is listed as one of the verified terminals, but for me it doesn't actually work:

With a dark background:

$ ./src/misc/termbg/target/release/termbg 
Check terminal background color
  Term : Tmux
  Latency: 630.001µs
  Color: R=0, G=0, B=0
  Theme: Dark

And with a light background:

$ ./src/misc/termbg/target/release/termbg 
Check terminal background color
  Term : Tmux
  Latency: 1.319794ms
  Color: R=0, G=0, B=0
  Theme: Dark

In both cases the detection appears to be error-free, but the background is detected incorrectly as dark.

Outside tmux (in a plain Konsole window), the color is detected correctly:

~$ ./src/misc/termbg/target/release/termbg 
Check terminal background color
  Term : XtermCompatible
  Latency: 1.449628ms
  Color: R=0, G=0, B=0
  Theme: Dark

~$ ./src/misc/termbg/target/release/termbg
Check terminal background color
  Term : XtermCompatible
  Latency: 2.596755ms
  Color: R=ffff, G=ffff, B=ffff
  Theme: Light

Interestingly, the color is detected correctly inside screen:

~$ ./src/misc/termbg/target/release/termbg
Check terminal background color
  Term : Screen
  Latency: 891.835µs
  Color: R=ffff, G=ffff, B=ffff
  Theme: Light

~$ ./src/misc/termbg/target/release/termbg
Check terminal background color
  Term : Screen
  Latency: 867.376µs
  Color: R=0, G=0, B=0
  Theme: Dark

Note that the tmux color isn't even recognized when the terminal is explicitly set to a particular color from within tmux:

~$ tmux set window-style 'fg=#d0cfcc,bg=#171421'

~$ ./src/misc/termbg/target/release/termbg
Check terminal background color
  Term : Tmux
  Latency: 409.917µs
  Color: R=0, G=0, B=0
  Theme: Dark

~$ tmux set window-style 'fg=#171421,bg=#ffffff'

~$ ./src/misc/termbg/target/release/termbg
Check terminal background color
  Term : Tmux
  Latency: 669.626µs
  Color: R=0, G=0, B=0
  Theme: Dark

Related: https://github.com/tmux/tmux/issues/1919