2 stable releases

True-colour ↔ ANSI terminal palette converter

ansi_colours is a library which converts between 24-bit sRGB colours
and 8-bit colour palette used by ANSI terminals such as xterm on
rxvt-unicode in 256-colour mode.

The most common use case is when using 24-bit colours in a terminal
emulator which only support 8-bit colour palette. This package allows
true-colours to be approximated by values supported by the terminal.

When mapping true-colour into available 256-colour palette (of which
only 240 are actually usable), this package tries to balance accuracy
and performance. It doesn’t implement the fastest algorithm nor is it
the most accurate, instead it uses a formula which should be fast
enough and accurate enough for most use-cases.

Usage

This library has C, C++ and Rust bindings and can be easily used from
any of those languages.

Rust

Using this package with Cargo projects is as simple as adding a single
dependency:

C and C++

The easiest way to use this package in C or C++ is to copy the
ansi_colour.h and ansi256.c files to your project (unfortunately,
C nor C++ has any centralised package repository), set up compilation
step for the ansi256.c file, add header file to include path and
once all that is done use the two functions provided by this library
can be used: