Code Monkey home page Code Monkey logo

coolor's Introduction

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

coolor's People

Contributors

canop avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

coolor's Issues

Crossterm is at version 0.25.0 now

Crossterm integration fails when using the latest version of crossterm (0.25.0 at time of writing).
I'm hoping this is a simple Cargo.toml change... if not, maybe I can open a PR.

Crossterm Reset != Black

Hi there. I was taking a read of the source and noticed that crossterm::Color::Reset gets translated to Black.

CC::Reset => 0.into(),

This is correct only for terminal themes that have their background color and black set to the same value (e.g. all light themes are excluded by this).

Visually, here's the output of the color example from Ratatui (note the color names are Ratatui names, not crossterm ones):

colors

I'm not sure what the right design for this should be in coolor as it seems like it would be use case dependent, but perhaps adding an explicit Reset variant to the color enum. Do you think it would be worth marking this as non-exhaustive to allow adding other color models?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.