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.



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

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

Instance Attribute Details

#codeObject (readonly)

Returns the value of attribute code.



7
8
9
# File 'lib/syntax_tree/cli.rb', line 7

def code
  @code
end

#valueObject (readonly)

Returns the value of attribute value.



7
8
9
# File 'lib/syntax_tree/cli.rb', line 7

def value
  @value
end

Class Method Details

.gray(value) ⇒ Object



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

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

.red(value) ⇒ Object



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

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

.yellow(value) ⇒ Object



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

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

Instance Method Details

#to_sObject



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

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