Module: Githug::UI
- Included in:
- Level
- Defined in:
- lib/githug/ui.rb
Constant Summary
collapse
- @@out_stream =
STDOUT
- @@in_stream =
STDIN
Class Method Summary
collapse
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
59
60
61
62
|
# File 'lib/githug/ui.rb', line 59
def method_missing(method, *args, &block)
return UI.send(method, *args) if UI.methods(false).include?(method.to_s) || UI.methods(false).include?(method)
super
end
|
Class Method Details
.ask(msg) ⇒ Object
40
41
42
|
# File 'lib/githug/ui.rb', line 40
def ask(msg)
request("#{msg} [yn] ") == 'y'
end
|
.colorize(text, color_code) ⇒ Object
44
45
46
47
|
# File 'lib/githug/ui.rb', line 44
def colorize(text, color_code)
return puts text if ENV['OS'] && ENV['OS'].downcase.include?("windows")
puts "#{color_code}#{text}\033[0m"
end
|
.error(text) ⇒ Object
49
50
51
|
# File 'lib/githug/ui.rb', line 49
def error(text)
colorize(text, "\033[31m")
end
|
.gets ⇒ Object
25
26
27
|
# File 'lib/githug/ui.rb', line 25
def gets
@@in_stream.gets
end
|
.in_stream=(in_stream) ⇒ Object
13
14
15
|
# File 'lib/githug/ui.rb', line 13
def in_stream=(in_stream)
@@in_stream = in_stream
end
|
.out_stream=(out) ⇒ Object
9
10
11
|
# File 'lib/githug/ui.rb', line 9
def out_stream=(out)
@@out_stream = out
end
|
.print(string) ⇒ Object
21
22
23
|
# File 'lib/githug/ui.rb', line 21
def print(string)
@@out_stream.print(string)
end
|
.puts(string = "") ⇒ Object
17
18
19
|
# File 'lib/githug/ui.rb', line 17
def puts(string = "")
@@out_stream.puts(string)
end
|
.request(msg) ⇒ Object
35
36
37
38
|
# File 'lib/githug/ui.rb', line 35
def request(msg)
print("#{msg} ")
gets.chomp
end
|
.success(text) ⇒ Object
53
54
55
|
# File 'lib/githug/ui.rb', line 53
def success(text)
colorize(text, "\033[32m")
end
|
.word_box(string, width = 80, char = '*') ⇒ Object
29
30
31
32
33
|
# File 'lib/githug/ui.rb', line 29
def word_box(string,width=80,char='*')
puts char*width
puts "#{char}#{string.center(width-2)}#{char}"
puts char*width
end
|