Module: Sai::Conversion::ColorSequence Private

Defined in:
lib/sai/conversion/color_sequence.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

ANSI escape sequence utilities

Author:

Since:

  • 0.1.0

Class Method Summary collapse

Class Method Details

.resolve(color, mode, style_type = :foreground) ⇒ String

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Convert a color to the appropriate ANSI escape sequence

Parameters:

  • color (String, Array<Integer>) —

    the color to convert

  • mode (Integer) —

    the terminal color mode

  • style_type (Symbol) (defaults to: :foreground) —

    the type of color (foreground or background)

Returns:

  • (String) —

    the ANSI escape sequence

Author:

Since:

  • 0.1.0



33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/sai/conversion/color_sequence.rb', line 33

def resolve(color, mode, style_type = :foreground)
  rgb = RGB.resolve(color)
  style_type = validate_style_type(style_type) #: style_type

  case mode
  when Terminal::ColorMode::TRUE_COLOR then true_color(rgb, style_type)
  when Terminal::ColorMode::ADVANCED then advanced(rgb, style_type)
  when Terminal::ColorMode::ANSI then ansi(rgb, style_type)
  when Terminal::ColorMode::BASIC then basic(rgb, style_type)
  else
    ''
  end
end