forked from Gazler/githug
/
ui.rb
73 lines (56 loc) · 1.22 KB
/
ui.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
module Githug
module UI
@@out_stream
@@in_stream
class << self
def out_stream=(out)
@@out_stream = out
end
def in_stream=(in_stream)
@@in_stream = in_stream
end
def puts(string = "")
@@out_stream.puts(string)
end
def print(string)
@@out_stream.print(string)
end
def gets
@@in_stream.gets
end
def line
puts("*"*80)
end
def word_box(string)
space_length = (80/2) - ((string.length/2)+1)
line
print "*"
print " "*space_length
print string
print " "*space_length
puts "*"
line
end
def request(msg)
print("#{msg} ")
gets.chomp
end
def ask(msg)
request("#{msg} [yn] ") == 'y'
end
def colorize(text, color_code)
puts "#{color_code}#{text}\033[0m"
end
def error(text)
colorize(text, "\033[31m")
end
def success(text)
colorize(text, "\033[32m")
end
end
def method_missing(method, *args, &block)
return UI.send(method, *args) if UI.methods(false).include?(method)
super
end
end
end