View Source Colorex.ANSI (Colorex v1.0.0)

Module for generating ANSI escape sequences, similar to IO.ANSI.

Generate ANSI escape sequences that display truecolor/24-bit color, or with truecolor mode off, it will find the closest 8-bit colors to match.

Summary

Functions

Returns an ANSI escape sequence setting the foreground color.

Returns an ANSI escape sequence setting the background color.

Types

color()

@type color() :: Colorex.Color.t() | colorspace_color()

color_key()

@type color_key() ::
  :red
  | :green
  | :blue
  | :alpha
  | :hue
  | :saturation
  | :lightness
  | :l
  | :a
  | :b
  | :cyan
  | :magenta
  | :yellow
  | :black
  | :x
  | :y
  | :z

colorspace_color()

@type colorspace_color() ::
  Colorex.RGB.t()
  | Colorex.HSL.t()
  | Colorex.LAB.t()
  | Colorex.XYZ.t()
  | Colorex.CMYK.t()

float_0_to_1()

@type float_0_to_1() :: float()

integer_0_to_255()

@type integer_0_to_255() :: pos_integer()

rgba_tuple()

@type rgba_tuple() ::
  {integer_0_to_255(), integer_0_to_255(), integer_0_to_255(), float_0_to_1()}

Functions

ansi(color, opts \\ [truecolor: true, fast: true])

@spec ansi(color :: color(), truecolor: boolean(), fast: boolean()) :: String.t()

Returns an ANSI escape sequence setting the foreground color.

See IO.ANSI for more information

## Options:

truecolor - whether to use the full 24-bit color spectrum, or just the standard 256 terminal colors. If you pass truecolor: false with a color that is not part of the 256 colors, the closest matching color will be chosen. Default: true

fast - uses the faster color comparison algorithm if true, or the more accurate one if false. See distance/3 for more info. Default: true

  iex> IO.puts(Colorex.ansi(Colorex.parse!("#1188FF")) <> "Blue text" <> IO.ANSI.reset())

ansi_background(color, opts \\ [truecolor: true, fast: true])

@spec ansi_background(color :: color(), truecolor: boolean(), fast: boolean()) ::
  String.t()

Returns an ANSI escape sequence setting the background color.

See IO.ANSI for more information

Options:

truecolor - whether to use the full 24-bit color spectrum, or just the standard 256 terminal colors. If you pass truecolor: false with a color that is not part of the 256 colors, the closest matching color will be chosen. Default: true

fast - uses the faster color comparison algorithm if true, or the more accurate one if false. See distance/3 for more info. Default: true

  iex> IO.puts(Colorex.ansi_background(Colorex.parse!("#1188FF")) <> "Blue background" <> IO.ANSI.reset())