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.



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

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

Instance Attribute Details

#codeObject (readonly)

Returns the value of attribute code.



9
10
11
# File 'lib/syntax_tree/cli.rb', line 9

def code
  @code
end

#valueObject (readonly)

Returns the value of attribute value.



9
10
11
# File 'lib/syntax_tree/cli.rb', line 9

def value
  @value
end

Class Method Details

.bold(value) ⇒ Object



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

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

.gray(value) ⇒ Object



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

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

.red(value) ⇒ Object



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

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

.yellow(value) ⇒ Object



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

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

Instance Method Details

#to_sObject



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

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