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.



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

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

Instance Attribute Details

#codeObject (readonly)

Returns the value of attribute code.



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

def code
  @code
end

#valueObject (readonly)

Returns the value of attribute value.



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

def value
  @value
end

Class Method Details

.bold(value) ⇒ Object



29
30
31
# File 'lib/syntax_tree/cli.rb', line 29

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

.gray(value) ⇒ Object



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

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

.red(value) ⇒ Object



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

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

.yellow(value) ⇒ Object



41
42
43
# File 'lib/syntax_tree/cli.rb', line 41

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

Instance Method Details

#to_sObject



25
26
27
# File 'lib/syntax_tree/cli.rb', line 25

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