termbg
A Rust library for terminal background color detection. The detected color is provided by RGB or theme ( dark or light ).
Verified terminals
- Alacritty
- GNOME Terminal
- GNU Screen
- macOS terminal
- MATE Terminal
- mintty
- RLogin
- rxvt-unicode
- sakura
- Tera Term
- Terminator
- tmux
- xfce4-terminal
- xterm
- Win32 console
"Windows Terminal" will be supported in a future release: https://github.com/microsoft/terminal/issues/3718.
If you check other terminals, please report through issue.
Unsupported terminals
- LilyTerm
- Poderosa
- PuTTY
- QTerminal
Usage
[]
= "0.2.0"
Example
Check program
This crate provides a simple program to check.
$ cargo run
Check terminal background color
Term : Tmux
Color: R=0, G=0, B=0
Theme: Dark
Detecting mechanism
If the terminal is win32 console, WIN32API is used for detection. If the terminal is xterm compatible, "Xterm Control Sequences" is used.
The detected RGB is converted to YCbCr. If Y > 0.5, the theme is detected as "light", otherwise "dark".