Module: Hansi

Defined in:
lib/hansi.rb,
lib/hansi/color.rb,
lib/hansi/theme.rb,
lib/hansi/themes.rb,
lib/hansi/special.rb,
lib/hansi/version.rb,
lib/hansi/palettes.rb,
lib/hansi/ansi_code.rb,
lib/hansi/color_parser.rb,
lib/hansi/mode_detector.rb,
lib/hansi/sexp_renderer.rb,
lib/hansi/color_renderer.rb,
lib/hansi/string_renderer.rb

Defined Under Namespace

Classes: AnsiCode, Color, ColorParser, ColorRenderer, ModeDetector, SexpRenderer, Special, StringRenderer, Theme

Constant Summary collapse

TRUE_COLOR =
256**3
VERSION =
'0.2.0'

Class Method Summary collapse

Class Method Details

.[](*args) ⇒ Object


4
5
6
# File 'lib/hansi.rb', line 4

def self.[](*args)
  ColorParser.parse(*args)
end

.color_namesObject


37
38
39
# File 'lib/hansi.rb', line 37

def self.color_names
  PALETTES['web'].keys
end

.modeObject


8
9
10
# File 'lib/hansi.rb', line 8

def self.mode
  @mode ||= mode_for(ENV)
end

.mode=(value) ⇒ Object


12
13
14
# File 'lib/hansi.rb', line 12

def self.mode=(value)
  @mode = value
end

.mode_for(env, **options) ⇒ Object


16
17
18
# File 'lib/hansi.rb', line 16

def self.mode_for(env, **options)
  ModeDetector.new(env, **options).mode
end

.render(*input, **options) ⇒ Object


20
21
22
# File 'lib/hansi.rb', line 20

def self.render(*input, **options)
  renderer_for(input.first).render(*input, **options)
end

.renderer_for(input) ⇒ Object


24
25
26
27
28
29
30
31
# File 'lib/hansi.rb', line 24

def self.renderer_for(input)
  case input
  when String        then StringRenderer
  when Symbol, Array then SexpRenderer
  when AnsiCode      then ColorRenderer
  else raise ArgumentError, "don't know how to render %p" % input
  end
end

.resetObject


33
34
35
# File 'lib/hansi.rb', line 33

def self.reset
  Hansi[:reset].to_ansi
end