Module: Uspec::Terminal
- Included in:
- Result
- Defined in:
- lib/uspec/terminal.rb
Class Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
38
39
40
41
42
43
44
|
# File 'lib/uspec/terminal.rb', line 38
def method_missing name, *args, &block
if colors.keys.include? name then
color name, *args
else
super
end
end
|
Class Method Details
.color(hue, text = nil) ⇒ Object
14
15
16
|
# File 'lib/uspec/terminal.rb', line 14
def color hue, text = nil
"#{esc "3#{colors[hue]};1"}#{text}#{normal unless text.nil?}"
end
|
.colors ⇒ Object
5
6
7
8
9
10
11
12
|
# File 'lib/uspec/terminal.rb', line 5
def colors
{
red: 1,
green: 2,
yellow: 3,
white: 7
}
end
|
.esc(seq) ⇒ Object
18
19
20
|
# File 'lib/uspec/terminal.rb', line 18
def esc seq
"\e[#{seq}m"
end
|
.hspace ⇒ Object
26
27
28
|
# File 'lib/uspec/terminal.rb', line 26
def hspace
' '
end
|
.method_missing(name, *args, &block) ⇒ Object
38
39
40
41
42
43
44
|
# File 'lib/uspec/terminal.rb', line 38
def method_missing name, *args, &block
if colors.keys.include? name then
color name, *args
else
super
end
end
|
.newline ⇒ Object
34
35
36
|
# File 'lib/uspec/terminal.rb', line 34
def newline
$/
end
|
.normal(text = nil) ⇒ Object
22
23
24
|
# File 'lib/uspec/terminal.rb', line 22
def normal text=nil
"#{esc 0}#{text}"
end
|
.vspace ⇒ Object
30
31
32
|
# File 'lib/uspec/terminal.rb', line 30
def vspace
"#{newline}#{newline}"
end
|