Get the Syntax of a Hexadecimal Color for the Terminal (ANSI RGB)

🎨 Easily copy the syntax and use it quickly.


Get the Syntax of a Hexadecimal Color for the Terminal (ANSI RGB)


I often create various CLI and TUI applications that heavily use ANSI color resources for the terminal. Usually, I need to pick the color in GIMP or rgb-tui and then assemble and test it to see how it will look.

To automate this step in development, I created hexter, which allows me to quickly and easily get the syntax of a hexadecimal color for the terminal (ANSI RGB).

I decided to build a command-line utility and also an API to integrate into my projects. And I chose to make it available for anyone interested.


📥 Installation

hexter was built with C++, so to compile and install it, you need the following installed on your system:

Then, just clone, build, and install:

git clone https://github.com/terroo/hexter  
cd hexter  
cmake . -B build  
cmake --build build  
sudo cmake --install build  

⚙️ Usage

The usage is simple and intuitive—just run the hexter command and provide the hexadecimal color with or without a hash (#):

When using a hash, enclose the color in single or double quotes.

hexter '#a6e22e'  
hexter fd6389  

If you have a file with your color theme, you can loop through it and get all the colors at once, for example:

cat theme.txt  

#121212  
#3a3b3f  
#5f5f5f  
#afafaf  
#eeeeee  
#ffffff  
#d7d7ff  
#7cdce7  
#84afd7  
#d7af87  
#2ec27e  
#fd6389  

for i in $(cat theme.txt); do hexter "$i"; done  

Output:

All hexter colors

This is the theme
sobrio


🔠 Use the API

You can also easily use the API to get the hexadecimal color—just include the header and use hexter::color. There’s also hexter::off to turn off a color, for example:

#include <print>  
#include "hexter-color.hpp"  

int main(){  
  std::println("{}Hello, World!{}", hexter::color("#84afd7"), hexter::off);  
}  

If you want to install the API to include it more easily directly in your system, run, for example:

sudo wget -q \  
  https://raw.githubusercontent.com/terroo/hexter/refs/heads/main/hexter-color.hpp \  
  -O /usr/local/include/hexter-color.hpp  

Then you can use it like this: #include <hexter-color.hpp>, as it is header-only.


For more information, send a PR, and/or report issues, visit the repository: https://github.com/terroo/hexter.


cpp cli commands terminal


Share


YouTube channel

Subscribe


Marcos Oliveira

Marcos Oliveira

Software developer
https://github.com/terroo

Related articles