Termbg 0.1.0, terminal background color detection / Call for cooperation to test

I released termbg 0.1.0.
This is a crate to detect terminal background color.

The detecting mechanism is terminal-specific (maybe version-specific), so tests on many terminals and environments are required.
If you are interesting in this crate, could you help to test as the following sequence?

$ cargo install termbg
$ termbg
Check terminal background color
  Term : Tmux
  Color: R=0, G=0, B=0
  Theme: Dark
$ cargo uninstall termbg

I want to know the output of termbg and your environment like below:

  • OS
  • terminal name/version
  • terminal multiplexer (ex. tmux/screen) name/version if it is used

Nice. This would be useful as part of a termcolor/ncurses library, even if guessing is the best possible general result. You've probably done your own research, but here are some links to people who have covered this ground before.

This one has a comment with a lot of informative links:

This one has a pretty thorough summary as well, and outlines the approach of emacs:

The main approaches other have taken which you don't seem to have covered yet is (1) a fallback for "known unknowns" like TERM=linux or putty or cygwin, and (2) whatever "OS specific interfaces" there are for DOS/Windows.

I ran into the former. The use case is working over SSH without forwarded environment. The TERM is linux and the actual background color is black.

Check terminal background color
  Term : Xterm
  Color: R=3333, G=3333, B=3333
  Theme: Dark

The end result (Dark) ended up being correct, but the colors are not. I was also thrown by "Term: Xterm" before I realized it meant "default fallback which is assumed to be an Xterm variant".

Thank you for a lot of information.
I referred to vim/emacs approach.

I think "known unknown" should be failed as a library, because the way of fallback is application-specific.
I'll add windows consle support through WIN32API at the next release.

The result of your environment seems to be correct.
The detected color is #333333, it looks like black.
The result means your terminal responsed to "Xterm Control Sequence".
"Term : Xterm" may be misleading, it should be "Term: Xterm-compatible".

Anyway, thank you again for your interesting in this crate!


I released v0.2.0.

  • Add custom Error type and timeout setting to API.
  • Windows platform and Win32 console support
  • Remove unnecessary dependencies
  • Remove rxvt approach ( it seems to be obsolete )

I updated verified terminals list too.

1 Like

It works for xfce4-terminal (on XFCE, ArchLinux, Linux 5.4.74-1).

Check terminal background color
  Term : XtermCompatible
  Color: R=0, G=0, B=0
  Theme: Dark

Works also on the same terminal, with screen :

Check terminal background color
  Term : Screen
  Color: R=0, G=0, B=0
  Theme: Dark
1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.