A Go library for terminal background color detection

go-termbg

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

Based on https://github.com/dalance/termbg for Rust

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.

Check program

This module provides a simple program to check.

$ go run ./...
Check terminal background color
  Term : XtermCompatible
  Color: R=2e2e, G=3434, B=3636
  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".

Owner
Anders Björklund
System developer working with continuous integration and delivery, using distributed build systems based on Linux and Open Source.
Anders Björklund
Similar Resources

Terminal UI library with rich, interactive widgets — written in Golang

Terminal UI library with rich, interactive widgets — written in Golang

Rich Interactive Widgets for Terminal UIs This Go package provides commonly needed components for terminal based user interfaces. Among these componen

Jan 7, 2023

A very simple library for interactively selecting an option on a terminal

A very simple library for interactively selecting an option on a terminal

go-choice A very simple library for interactively selecting an option on a terminal Usage package main import ( "fmt" "github.com/TwiN/go-ch

Dec 30, 2021

Qalam - An easy to use terminal styling library

Qalam - An easy to use terminal styling library

Qalam ✏️ Qalam is a Go library for easy terminal styling. Installation go get gi

Jan 6, 2023

Terminal client for SimpleNote

GoNote - Terminal client for SimpleNote GoNote is a simple utility for managing notes in your SimpleNote account. It allows basic operations like crea

Nov 22, 2022

gomerge is a tool to quickly bulk merge several pull requests from your terminal.

gomerge is a tool to quickly bulk merge several pull requests from your terminal.

Gomerge is a tool to quickly enable you to bulk merge Github pull requests from your terminal. The intention of this tool is to simplfy, and eventually automate the merging of github pull requests. This tool should be able to run on most systems.

Dec 28, 2022

`tmax` is a powerful tool to help you get terminal cmd directly.

`tmax`  is a powerful tool to help you get terminal cmd directly.

The positioning of tmax is a command line tool with a little artificial intelligence. If you frequently deal with the terminal daily, tmax will greatly improve your work efficiency.

Oct 15, 2022

YouTube client on your terminal

MeowTube YouTube client on your terminal Table of Contents About Getting Started Usage Contributing About MeowTube is a CLI (Command Line Interface) t

Jul 29, 2022

🎄 A Christmas tree right from your terminal!

🎄 A Christmas tree right from your terminal!

ctree 🎄 A Christmas tree right from your terminal! 👀 Demo ⌛ No Refresh Don't want the tree to refresh every 2 seconds? Easy! Just add the --no-refre

Dec 20, 2022

progress_bar creates a single customizable progress bar for Linux terminal.

progress_bar creates a single customizable progress bar for Linux terminal.

progress_bar Go Progress Bar Features progress_bar creates a single customizable progress bar for Linux terminal. Installation go get -u github.com/er

Aug 12, 2022
Comments
  • Color and theme fail for tmux and screen

    Color and theme fail for tmux and screen

    I'm finding that the color and theme detection are failing when using tmux or screen. For example:

    # tmux 3.0a
    $ go run ./cmd/...
    Check terminal background color
      Term : Tmux
      Color: detection failed unknown
      Theme: detection failed unknown
    
    # GNU Screen 4.08.00
    $ go run ./cmd/...
    Check terminal background color
      Term : Screen
      Color: detection failed unknown
      Theme: detection failed unknown
    

    I don't see any handling for these cases in the NewRGB function. I was able to resolve the issue for my configuration (although I don't know if it is a good general solution) by doing this:

    diff --git a/pkg/termbg/rgb_unix.go b/pkg/termbg/rgb_unix.go
    index 0867491..f95c3bf 100644
    --- a/pkg/termbg/rgb_unix.go
    +++ b/pkg/termbg/rgb_unix.go
    @@ -15,7 +15,7 @@ func NewRGB(timeout time.Duration) (RGB, error) {
                    return RGB{}, fmt.Errorf("unsupported")
            case RxvtCompatible:
                    return fromRxvt()
    -       case XtermCompatible:
    +       case XtermCompatible, Tmux, Screen:
                    return fromXterm(term, timeout)
            default:
                    return RGB{}, fmt.Errorf("unknown")
    
A Go package for converting RGB and other color formats/colorspaces into DMC thread colors (DMC color name and floss number)

go-c2dmc A Go package for converting RGB and other color formats/colorspaces into DMC thread colors (DMC color name and floss number). Implemented as

Jul 25, 2022
Chalk is a Go Package which can be used for making terminal output more vibrant with text colors, text styles and background colors.
Chalk is a Go Package which can be used for making terminal output more vibrant with text colors, text styles and background colors.

Chalk Chalk is a Go Package which can be used for making terminal output more vibrant with text colors, text styles and background colors. Documentati

Oct 29, 2022
Draw images in your ANSI terminal with true color
Draw images in your ANSI terminal with true color

___ _____ ____ / _ \/ _/ |/_/ /____ ______ _ Made with love by Eliuk Blau / ___// /_> </ __/ -_) __/ ' \ https://github.com/eliukblau/pix

Dec 14, 2022
Advanced ANSI style & color support for your terminal applications
Advanced ANSI style & color support for your terminal applications

termenv lets you safely use advanced styling options on the terminal. It gathers information about the terminal environment in terms of its ANSI & col

Dec 31, 2022
A simple logging interface that supports cross-platform color and concurrency.
A simple logging interface that supports cross-platform color and concurrency.

WLog Package wlog creates simple to use UI structure. The UI is used to simply print to the screen. There a wrappers that will wrap each other to crea

Sep 26, 2022
Color package for Go (golang)
Color package for Go (golang)

color Color lets you use colorized outputs in terms of ANSI Escape Codes in Go (Golang). It has support for Windows too! The API can be used in severa

Dec 31, 2022
Color quantization experiment for golang

bitcrush Color quantization experiment, version 4 Build git clone https://github

Jun 15, 2022
donLoader is a shellcode loader creation tool that uses donut to convert executable payloads into shellcode to evade detection on disk.

donLoader WARNING: This is WIP, barely anything was tested properly. Use at your own risk. Description donLoader is a shellcode loader creation tool t

Sep 20, 2022
Stonks is a terminal based stock visualizer and tracker that displays realtime stocks in graph format in a terminal.
Stonks is a terminal based stock visualizer and tracker that displays realtime stocks in graph format in a terminal.

Stonks is a terminal based stock visualizer and tracker. Installation Requirements: golang >= 1.13 Manual Clone the repo Run make && make install Pack

Dec 16, 2022
A UI library for terminal applications.
A UI library for terminal applications.

tui: Terminal UI for Go A UI library for terminal applications. tui (pronounced tooey) provides a higher-level programming model for building rich ter

Jan 6, 2023