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

🎨 Easily copy the syntax and use it quickly.

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…


This content originally appeared on DEV Community and was authored by Marcos Oliveira

🎨 Easily copy the syntax and use it quickly.

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.


This content originally appeared on DEV Community and was authored by Marcos Oliveira


Print Share Comment Cite Upload Translate Updates
APA

Marcos Oliveira | Sciencx (2025-07-01T16:07:04+00:00) Get the Syntax of a Hexadecimal Color for the Terminal (ANSI RGB). Retrieved from https://www.scien.cx/2025/07/01/get-the-syntax-of-a-hexadecimal-color-for-the-terminal-ansi-rgb/

MLA
" » Get the Syntax of a Hexadecimal Color for the Terminal (ANSI RGB)." Marcos Oliveira | Sciencx - Tuesday July 1, 2025, https://www.scien.cx/2025/07/01/get-the-syntax-of-a-hexadecimal-color-for-the-terminal-ansi-rgb/
HARVARD
Marcos Oliveira | Sciencx Tuesday July 1, 2025 » Get the Syntax of a Hexadecimal Color for the Terminal (ANSI RGB)., viewed ,<https://www.scien.cx/2025/07/01/get-the-syntax-of-a-hexadecimal-color-for-the-terminal-ansi-rgb/>
VANCOUVER
Marcos Oliveira | Sciencx - » Get the Syntax of a Hexadecimal Color for the Terminal (ANSI RGB). [Internet]. [Accessed ]. Available from: https://www.scien.cx/2025/07/01/get-the-syntax-of-a-hexadecimal-color-for-the-terminal-ansi-rgb/
CHICAGO
" » Get the Syntax of a Hexadecimal Color for the Terminal (ANSI RGB)." Marcos Oliveira | Sciencx - Accessed . https://www.scien.cx/2025/07/01/get-the-syntax-of-a-hexadecimal-color-for-the-terminal-ansi-rgb/
IEEE
" » Get the Syntax of a Hexadecimal Color for the Terminal (ANSI RGB)." Marcos Oliveira | Sciencx [Online]. Available: https://www.scien.cx/2025/07/01/get-the-syntax-of-a-hexadecimal-color-for-the-terminal-ansi-rgb/. [Accessed: ]
rf:citation
» Get the Syntax of a Hexadecimal Color for the Terminal (ANSI RGB) | Marcos Oliveira | Sciencx | https://www.scien.cx/2025/07/01/get-the-syntax-of-a-hexadecimal-color-for-the-terminal-ansi-rgb/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.