MCPcopy Index your code
hub / github.com/dalance/termbg

github.com/dalance/termbg @v0.6.2

Chat with this repo
repository ↗ · DeepWiki ↗ · release v0.6.2 ↗ · + Follow
33 symbols 67 edges 2 files 4 documented · 12%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

termbg

A Rust library for terminal background color detection. The detected color is provided by RGB or theme ( dark or light ).

Actions Status Crates.io Docs.rs

Verified terminals

If you check other terminals, please report through issue.

Unsupported terminals

"Windows Terminal" may be supported in a future release: https://github.com/microsoft/terminal/issues/3718.

Usage

[dependencies]
termbg = "0.6.2"

Example

fn main() {
    let timeout = std::time::Duration::from_millis(100);

    println!("Check terminal background color");
    let term = termbg::terminal();
    let rgb = termbg::rgb(timeout);
    let theme = termbg::theme(timeout);

    println!("  Term : {:?}", term);

    match rgb {
        Ok(rgb) => {
            println!("  Color: R={:x}, G={:x}, B={:x}", rgb.r, rgb.g, rgb.b);
        }
        Err(e) => {
            println!("  Color: detection failed {:?}", e);
        }
    }

    match theme {
        Ok(theme) => {
            println!("  Theme: {:?}", theme);
        }
        Err(e) => {
            println!("  Theme: detection failed {:?}", e);
        }
    }
}

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. When these method was failed, COLORFGBG environment variable is used.

The detected RGB is converted to YCbCr. If Y > 0.5, the theme is detected as "light", otherwise "dark".

Extension points exported contracts — how you extend this code

EventReader (Interface)
(no doc) [1 implementers]
src/lib.rs

Core symbols most depended-on inside this repo

terminal
called by 5
src/lib.rs
run_query_xterm_test
called by 5
src/lib.rs
decode_hex
called by 3
src/lib.rs
rgb
called by 2
src/lib.rs
enable_virtual_terminal_processing
called by 2
src/lib.rs
from_xterm
called by 2
src/lib.rs
query_xterm
called by 2
src/lib.rs
parse_response
called by 2
src/lib.rs

Shape

Function 25
Enum 3
Class 2
Method 2
Interface 1

Languages

Rust100%

Modules by API surface

src/lib.rs32 symbols
src/bin/termbg.rs1 symbols

For agents

$ claude mcp add termbg \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact