16 releases (1 stable)

1.0.0 Aug 12, 2024
0.9.0 Jan 14, 2024
0.8.0 Oct 31, 2023
0.5.1 Dec 15, 2022
0.3.1 Nov 26, 2021

#17 in No standard library

Download history 12406/week @ 2024-07-22 12315/week @ 2024-07-29 10506/week @ 2024-08-05 11042/week @ 2024-08-12 9183/week @ 2024-08-19 11076/week @ 2024-08-26 9495/week @ 2024-09-02 11029/week @ 2024-09-09 11294/week @ 2024-09-16 11518/week @ 2024-09-23 13162/week @ 2024-09-30 12433/week @ 2024-10-07 9681/week @ 2024-10-14 11645/week @ 2024-10-21 11910/week @ 2024-10-28 11841/week @ 2024-11-04

45,630 downloads per month
Used in 91 crates (3 directly)

MIT license

140KB
3.5K SLoC

MIT Latest Version docs Chat on Miaou

Definition of ANSI, RGB and HSL color types and all the conversions between them.

There are many other color conversion crates. This one is no-std and pure-rust and may be useful when you're interested into

  • variations of an ANSI color for your TUI application, for example fading, lightening, darkening, with compatibility with terminals that don't support RGB.
  • translations of color schemes
  • automatic downgrading of RGB color schemes for non RGB terminals
  • automated building of harmonious color schemes with guarantees of contrast
  • etc.

Coolor is used in SafeCloset to dynamically fade the background behind a dialog:

img

Be warned that the ANSI range is intrinsically limited to 240 colors and that not all intuitive operations will give good results.

Coolor doesn't contain functions to print on the terminal, but the colors can be used in other crates. There's an optional feature for conversion from and into Crossterm colors. You'll see it used in the included examples.

Included Examples

ansi-variations

Luminosity and saturation variations of all 240 ANSI colors, with all variants still ANSI colors.

ansi-variations

ansi-mix

Several ways to mix colors

ansi-mix

rgb-to-ansi

Finding the nearest ANSI color from a RGB one

rgb-to-ansi

Dependencies

~0–8.5MB
~81K SLoC