loquacious 1.2.0 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +5 -0
- data/lib/loquacious.rb +1 -1
- data/lib/loquacious/configuration/help.rb +82 -2
- data/loquacious.gemspec +1 -1
- metadata +1 -1
data/History.txt
CHANGED
data/lib/loquacious.rb
CHANGED
@@ -18,7 +18,14 @@ class Loquacious::Configuration
|
|
18
18
|
:name_leader => ' - '.freeze,
|
19
19
|
:name_length => 0,
|
20
20
|
:name_value_sep => ' => '.freeze,
|
21
|
-
:desc_leader => ' '.freeze
|
21
|
+
:desc_leader => ' '.freeze,
|
22
|
+
:colorize => false,
|
23
|
+
:colors => {
|
24
|
+
:name => :white,
|
25
|
+
:value => :cyan,
|
26
|
+
:description => :green,
|
27
|
+
:leader => :yellow
|
28
|
+
}.freeze
|
22
29
|
}.freeze
|
23
30
|
|
24
31
|
class Error < StandardError; end
|
@@ -34,6 +41,12 @@ class Loquacious::Configuration
|
|
34
41
|
# :name_value_sep String separating the attribute name from the value
|
35
42
|
# :desc_leader String appearing before the description
|
36
43
|
# :io The IO object where help will be written
|
44
|
+
# :colorize Flag to colorize the output or not
|
45
|
+
# :colors Hash of colors for the name, value, description
|
46
|
+
# :name Name color
|
47
|
+
# :value Value color
|
48
|
+
# :description Description color
|
49
|
+
# :leader Leader and spacer color
|
37
50
|
#
|
38
51
|
# The description is printed before each attribute name and value on its
|
39
52
|
# own line.
|
@@ -46,6 +59,8 @@ class Loquacious::Configuration
|
|
46
59
|
@io = opts[:io]
|
47
60
|
@name_length = Integer(opts[:name_length])
|
48
61
|
@desc_leader = opts[:desc_leader]
|
62
|
+
@colorize = opts[:colorize]
|
63
|
+
@colors = opts[:colors]
|
49
64
|
|
50
65
|
unless @name_length > 0
|
51
66
|
Iterator.new(@config).each do |node|
|
@@ -64,12 +79,33 @@ class Loquacious::Configuration
|
|
64
79
|
@format = "#{name_leader}%-#{@name_length}s#{name_value_sep}%s"
|
65
80
|
@name_format = "#{name_leader}%s"
|
66
81
|
|
82
|
+
if colorize?
|
83
|
+
@desc_leader = self.__send__(@colors[:leader], @desc_leader)
|
84
|
+
name_leader = self.__send__(@colors[:leader], name_leader)
|
85
|
+
name_value_sep = self.__send__(@colors[:leader], name_value_sep)
|
86
|
+
|
87
|
+
@format = name_leader.dup
|
88
|
+
@format << self.__send__(@colors[:name], "%-#{@name_length}s")
|
89
|
+
@format << name_value_sep.dup
|
90
|
+
@format << self.__send__(@colors[:value], "%s")
|
91
|
+
|
92
|
+
@name_format = name_leader.dup
|
93
|
+
@name_format << self.__send__(@colors[:name], "%s")
|
94
|
+
end
|
95
|
+
|
67
96
|
@desc_leader.freeze
|
68
97
|
@value_leader.freeze
|
69
98
|
@format.freeze
|
70
99
|
@name_format.freeze
|
71
100
|
end
|
72
101
|
|
102
|
+
# Returns +true+ if the help instance is configured to colorize the
|
103
|
+
# output messages. Returns +false+ otherwise.
|
104
|
+
#
|
105
|
+
def colorize?
|
106
|
+
@colorize
|
107
|
+
end
|
108
|
+
|
73
109
|
# call-seq:
|
74
110
|
# show_attribute( name = nil, opts = {} )
|
75
111
|
#
|
@@ -128,7 +164,15 @@ class Loquacious::Configuration
|
|
128
164
|
def print_node( node, show_description, show_value )
|
129
165
|
desc = node.desc.to_s.dup
|
130
166
|
show_description = false if desc.empty?
|
131
|
-
|
167
|
+
|
168
|
+
if show_description
|
169
|
+
if colorize?
|
170
|
+
desc = desc.gsub(%r/([^\n]+)/,
|
171
|
+
self.__send__(@colors[:description], '\1'))
|
172
|
+
end
|
173
|
+
@io.puts(desc.indent(@desc_leader))
|
174
|
+
end
|
175
|
+
|
132
176
|
@io.puts(format_name(node, show_value))
|
133
177
|
@io.puts if show_description
|
134
178
|
end
|
@@ -148,6 +192,42 @@ class Loquacious::Configuration
|
|
148
192
|
@format % [name, obj]
|
149
193
|
end
|
150
194
|
|
195
|
+
[ [ :clear , 0 ],
|
196
|
+
[ :reset , 0 ], # synonym for :clear
|
197
|
+
[ :bold , 1 ],
|
198
|
+
[ :dark , 2 ],
|
199
|
+
[ :italic , 3 ], # not widely implemented
|
200
|
+
[ :underline , 4 ],
|
201
|
+
[ :underscore , 4 ], # synonym for :underline
|
202
|
+
[ :blink , 5 ],
|
203
|
+
[ :rapid_blink , 6 ], # not widely implemented
|
204
|
+
[ :negative , 7 ], # no reverse because of String#reverse
|
205
|
+
[ :concealed , 8 ],
|
206
|
+
[ :strikethrough, 9 ], # not widely implemented
|
207
|
+
[ :black , 30 ],
|
208
|
+
[ :red , 31 ],
|
209
|
+
[ :green , 32 ],
|
210
|
+
[ :yellow , 33 ],
|
211
|
+
[ :blue , 34 ],
|
212
|
+
[ :magenta , 35 ],
|
213
|
+
[ :cyan , 36 ],
|
214
|
+
[ :white , 37 ],
|
215
|
+
[ :on_black , 40 ],
|
216
|
+
[ :on_red , 41 ],
|
217
|
+
[ :on_green , 42 ],
|
218
|
+
[ :on_yellow , 43 ],
|
219
|
+
[ :on_blue , 44 ],
|
220
|
+
[ :on_magenta , 45 ],
|
221
|
+
[ :on_cyan , 46 ],
|
222
|
+
[ :on_white , 47 ] ].each do |name,code|
|
223
|
+
|
224
|
+
class_eval <<-CODE
|
225
|
+
def #{name.to_s}( str )
|
226
|
+
"\e[#{code}m\#{str}\e[0m"
|
227
|
+
end
|
228
|
+
CODE
|
229
|
+
end
|
230
|
+
|
151
231
|
end # class Help
|
152
232
|
end # module Loquacious
|
153
233
|
|
data/loquacious.gemspec
CHANGED