1
|
|
|
require_relative "colours" |
2
|
|
|
|
3
|
|
|
module Resume |
4
|
|
|
# Wrapper module around printing to `$stdout` that can deal with CLI |
5
|
|
|
# colours and internationalisation. |
6
|
|
|
# |
7
|
|
|
# @author Paul Fioravanti |
8
|
|
|
module Console |
9
|
|
|
module_function |
10
|
|
|
|
11
|
|
|
# Calls to appropriately output each type of message in the |
12
|
|
|
# given `messages`. |
13
|
|
|
# |
14
|
|
|
# @param messages [Hash] |
15
|
|
|
# A hash of messages where the keys describe the type of message to |
16
|
|
|
# output, and the values describe the i18n key for the message to ouput. |
17
|
|
|
# @return [Hash] the original hash of `messages`. |
18
|
|
|
def output(messages) |
19
|
|
|
messages.each { |type, key| public_send(type, key) } |
20
|
|
|
end |
21
|
|
|
|
22
|
|
|
# Outputs the translated message for `params` to `$stdout` in red |
23
|
|
|
# with a newline ending. |
24
|
|
|
# |
25
|
|
|
# @overload error(key) |
26
|
|
|
# @param key [Symbol] The message key to translate |
27
|
|
|
# @overload error(key, params) |
28
|
|
|
# @param key [Symbol] The message key to translate |
29
|
|
|
# @param params [Hash] The params to pass in to the translation message |
30
|
|
|
# @return [nil] |
31
|
|
|
def error(*params) |
32
|
|
|
puts Colours.red(I18n.translate(*params)) |
33
|
|
|
end |
34
|
|
|
|
35
|
|
|
# Outputs the translated message for `params` to `$stdout` in yellow |
36
|
|
|
# with a newline ending. |
37
|
|
|
# |
38
|
|
|
# @overload warning(key) |
39
|
|
|
# @param key [Symbol] The message key to translate |
40
|
|
|
# @overload warning(key, params) |
41
|
|
|
# @param key [Symbol] The message key to translate |
42
|
|
|
# @param params [Hash] The params to pass in to the translation message |
43
|
|
|
# @return [nil] |
44
|
|
|
def warning(*params) |
45
|
|
|
puts Colours.yellow(I18n.translate(*params)) |
46
|
|
|
end |
47
|
|
|
|
48
|
|
|
# Outputs the translated message for `params` to `$stdout` in yellow |
49
|
|
|
# without a newline ending. |
50
|
|
|
# |
51
|
|
|
# @overload question(key) |
52
|
|
|
# @param key [Symbol] The message key to translate |
53
|
|
|
# @overload question(key, params) |
54
|
|
|
# @param key [Symbol] The message key to translate |
55
|
|
|
# @param params [Hash] The params to pass in to the translation message |
56
|
|
|
# @return [nil] |
57
|
|
|
def question(*params) |
58
|
|
|
print Colours.yellow(I18n.translate(*params)) |
59
|
|
|
end |
60
|
|
|
|
61
|
|
|
# Outputs the translated message for `params` to `$stdout` in green |
62
|
|
|
# with a newline ending. |
63
|
|
|
# |
64
|
|
|
# @overload success(key) |
65
|
|
|
# @param key [Symbol] The message key to translate |
66
|
|
|
# @overload success(key, params) |
67
|
|
|
# @param key [Symbol] The message key to translate |
68
|
|
|
# @param params [Hash] The params to pass in to the translation message |
69
|
|
|
# @return [nil] |
70
|
|
|
def success(*params) |
71
|
|
|
puts Colours.green(I18n.translate(*params)) |
72
|
|
|
end |
73
|
|
|
|
74
|
|
|
# Outputs the translated message for `params` to `$stdout` in cyan |
75
|
|
|
# with a newline ending. |
76
|
|
|
# |
77
|
|
|
# @overload info(key) |
78
|
|
|
# @param key [Symbol] The message key to translate |
79
|
|
|
# @overload info(key, params) |
80
|
|
|
# @param key [Symbol] The message key to translate |
81
|
|
|
# @param params [Hash] The params to pass in to the translation message |
82
|
|
|
# @return [nil] |
83
|
|
|
def info(*params) |
84
|
|
|
puts Colours.cyan(I18n.translate(*params)) |
85
|
|
|
end |
86
|
|
|
|
87
|
|
|
# Outputs the translated message for `params` to `$stdout` in default |
88
|
|
|
# colour with a newline ending. |
89
|
|
|
# |
90
|
|
|
# @overload plain(key) |
91
|
|
|
# @param key [Symbol] The message key to translate |
92
|
|
|
# @overload plain(key, params) |
93
|
|
|
# @param key [Symbol] The message key to translate |
94
|
|
|
# @param params [Hash] The params to pass in to the translation message |
95
|
|
|
# @return [nil] |
96
|
|
|
def plain(*params) |
97
|
|
|
puts I18n.translate(*params) |
98
|
|
|
end |
99
|
|
|
|
100
|
|
|
# Outputs the `message` parameter to `$stdout` in red |
101
|
|
|
# with a newline ending. |
102
|
|
|
# |
103
|
|
|
# @param (see #raw) |
104
|
|
|
# @return (see #raw) |
105
|
|
|
def raw_error(message) |
106
|
|
|
puts Colours.red(message) |
107
|
|
|
end |
108
|
|
|
|
109
|
|
|
# Outputs the `message` parameter to `$stdout` in yellow |
110
|
|
|
# with a newline ending. |
111
|
|
|
# |
112
|
|
|
# @param (see #raw) |
113
|
|
|
# @return (see #raw) |
114
|
|
|
def raw_warning(message) |
115
|
|
|
puts Colours.yellow(message) |
116
|
|
|
end |
117
|
|
|
|
118
|
|
|
# Outputs the `message` parameter to `$stdout` in green |
119
|
|
|
# with a newline ending. |
120
|
|
|
# |
121
|
|
|
# @param (see #raw) |
122
|
|
|
# @return (see #raw) |
123
|
|
|
def raw_success(message) |
124
|
|
|
puts Colours.green(message) |
125
|
|
|
end |
126
|
|
|
|
127
|
|
|
# Outputs the `message` parameter to `$stdout` in default colour |
128
|
|
|
# with a newline ending. |
129
|
|
|
# |
130
|
|
|
# @param message [String] The message to output |
131
|
|
|
# @return [nil] |
132
|
|
|
def raw(message) |
133
|
|
|
puts message |
134
|
|
|
end |
135
|
|
|
end |
136
|
|
|
end |
137
|
|
|
|