Skip to content

Latest commit

 

History

History
102 lines (72 loc) · 3.2 KB

README.md

File metadata and controls

102 lines (72 loc) · 3.2 KB

Build Status Version License

Term Colors

Term_colors is a library containing color manipulation routines for term/console applications.

Terminal apps can use 5 different palettes:

  1. Monochrome (2-color)
  2. Low color (8-color)
  3. ANSI / XTerm color (16-color)
  4. High color (256-color)
  5. TrueColor (16M-color/24-bit color)

This module provides color-related functions for the first 4 types. TrueColor is not supported yet.

Installation

Add the dependency to shard.yml:

dependencies:
  term_colors:
    github: crystallabs/term_colors
    version: ~> 1.0

Available functions

# Takes color value and returns index of the nearest/closest
# matching color in the current palette.
  def match( r1 : String)
  def match( r1 : Array)
  def match( r1 : Tuple)
  def match(r1, g1, b1)

# Calculates color distance.
  def color_distance(r1, g1, b1, r2, g2, b2)

# Converts RGB to hex color value (#color).
  def rgb_to_hex(r : Array)
  def rgb_to_hex(r : Colorize::ColorRGB)
  def rgb_to_hex(r, g, b)

# Converts number to hex value with 2 places.
  def to_hex2(n)

# Converts number to hex value with 4 places.
  def to_hex4(n)

# Converts hex color value (#col or #color) to {r,g,b}.
  def hex_to_rgb(hex : String)

# Mixes colors.
  def mix_colors(c1, c2, alpha=0.5)

# Blends two attributes together, taking into account alpha/transparency value.
  def blend(attr, attr2, alpha)

# Converts color into lower/smaller color space.
  def reduce(color, total)

# Converts color to index in the current palette.
  def convert(color : Int)
  def convert(color : String)
  def convert(color : Array)
  def convert(color)

Testing

Run crystal spec as usual.

Documentation

Run crystal docs as usual.

Thanks

Other projects

List of interesting or similar projects in no particular order:

Colors-related:

Terminal-related: