Class: SyntaxTree::CLI::Color

Inherits:
Object
  • Object
show all
Defined in:
lib/syntax_tree/cli.rb

Overview

A utility wrapper around colored strings in the output.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value, code) ⇒ Color

Returns a new instance of Color.



14
15
16
17
# File 'lib/syntax_tree/cli.rb', line 14

def initialize(value, code)
  @value = value
  @code = code
end

Instance Attribute Details

#codeObject (readonly)

Returns the value of attribute code.



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

def code
  @code
end

#valueObject (readonly)

Returns the value of attribute value.



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

def value
  @value
end

Class Method Details

.bold(value) ⇒ Object



23
24
25
# File 'lib/syntax_tree/cli.rb', line 23

def self.bold(value)
  new(value, "1")
end

.gray(value) ⇒ Object



27
28
29
# File 'lib/syntax_tree/cli.rb', line 27

def self.gray(value)
  new(value, "38;5;102")
end

.red(value) ⇒ Object



31
32
33
# File 'lib/syntax_tree/cli.rb', line 31

def self.red(value)
  new(value, "1;31")
end

.yellow(value) ⇒ Object



35
36
37
# File 'lib/syntax_tree/cli.rb', line 35

def self.yellow(value)
  new(value, "33")
end

Instance Method Details

#to_sObject



19
20
21
# File 'lib/syntax_tree/cli.rb', line 19

def to_s
  "\033[#{code}m#{value}\033[0m"
end