yummi 0.5.2 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +5 -5
- data/bin/{colorize → yummi} +1 -1
- data/examples/cash_flow_table.rb +5 -1
- data/examples/cash_flow_table.yaml +11 -2
- data/examples/cash_flow_table_data.csv +1 -1
- data/examples/cash_flow_table_data.yaml +1 -1
- data/examples/cash_flow_table_extensions.rb +2 -2
- data/examples/license_box.rb +38 -7
- data/examples/list_files.rb +2 -2
- data/examples/monitor_table.rb +51 -24
- data/lib/yummi.rb +84 -50
- data/lib/yummi/color_mapping.rb +12 -24
- data/lib/yummi/colorizers.rb +47 -114
- data/lib/yummi/formatters.rb +14 -7
- data/lib/yummi/logger.rb +1 -1
- data/lib/yummi/mappings/weblogic11g.yaml +2 -2
- data/lib/yummi/table.rb +145 -57
- data/lib/yummi/table_builder.rb +13 -20
- data/lib/yummi/text_box.rb +84 -35
- data/lib/yummi/version.rb +1 -1
- metadata +4 -4
data/README.md
CHANGED
@@ -24,14 +24,14 @@ the examples dir to see how to use Yummi features.
|
|
24
24
|
|
25
25
|
## Command Line Tools
|
26
26
|
|
27
|
-
Yummi exposes a '
|
27
|
+
Yummi exposes a 'yummi' program that you can use to colorize texts and apply
|
28
28
|
patterns to colorize lines (usefull to tail logs).
|
29
29
|
|
30
30
|
Examples:
|
31
31
|
|
32
|
-
|
33
|
-
echo "some text" |
|
34
|
-
tail -f $JBOSS_HOME/standalone/log/server.log |
|
32
|
+
yummi -c intense_red -m "some text"
|
33
|
+
echo "some text" | yummi -c intense_red
|
34
|
+
tail -f $JBOSS_HOME/standalone/log/server.log | yummi -p path-to-your-jboss7-mapping.yaml
|
35
35
|
|
36
36
|
Line patterns are configured with an yaml file containing:
|
37
37
|
|
@@ -54,7 +54,7 @@ Yummi provides a set of mappings that you, check yummi/mappings dir.
|
|
54
54
|
|
55
55
|
Mappings provided by yummi can be passed with the file name, example:
|
56
56
|
|
57
|
-
tail -f $JBOSS_HOME/standalone/log/server.log |
|
57
|
+
tail -f $JBOSS_HOME/standalone/log/server.log | yummi -p jboss7
|
58
58
|
|
59
59
|
Mappings in ~/.yummi dir may also used only with the file name.
|
60
60
|
|
data/bin/{colorize → yummi}
RENAMED
@@ -46,7 +46,7 @@ end
|
|
46
46
|
opt.on '--data-type', 'Defines the data type to parse the values' do |data_type|
|
47
47
|
@data_type = data_type
|
48
48
|
end
|
49
|
-
opt.on '-e FILES', '--eval=FILES', Array, '
|
49
|
+
opt.on '-e FILES', '--eval=FILES', Array, 'Include the files for extending components' do |files|
|
50
50
|
files.each do |file|
|
51
51
|
load File.expand_path(file)
|
52
52
|
end
|
data/examples/cash_flow_table.rb
CHANGED
@@ -30,7 +30,7 @@ tablebuilder = Yummi::TableBuilder::new('cash_flow_table.yaml')
|
|
30
30
|
|
31
31
|
@table = tablebuilder.defaults.build_table
|
32
32
|
|
33
|
-
@table.data = [['Initial',
|
33
|
+
@table.data = [['Initial', nil, 0, nil, nil],
|
34
34
|
['Deposit', 100.58, 100.58, true, "QAWSEDRFTGH535"],
|
35
35
|
['Withdraw', -50.23, 50.35, true, "34ERDTF6GYU"],
|
36
36
|
['Withdraw', -100, -49.65, true, "2344EDRFT5"],
|
@@ -44,6 +44,10 @@ end
|
|
44
44
|
|
45
45
|
opt.on '--box', 'Prints the table inside a box' do
|
46
46
|
@box = Yummi::TextBox::new
|
47
|
+
@box.style.top_left = '/'
|
48
|
+
@box.style.bottom_left = '\\'
|
49
|
+
@box.style.top_right = '\\'
|
50
|
+
@box.style.bottom_right = '/'
|
47
51
|
end
|
48
52
|
opt.on '--help', 'Prints this message' do
|
49
53
|
puts opt
|
@@ -35,7 +35,7 @@ color:
|
|
35
35
|
row_color:
|
36
36
|
blessed_income: yellow
|
37
37
|
|
38
|
-
|
38
|
+
top:
|
39
39
|
- format:
|
40
40
|
total:
|
41
41
|
numeric:
|
@@ -43,4 +43,13 @@ contexts:
|
|
43
43
|
zero: "%.2f"
|
44
44
|
negative: "%.2f"
|
45
45
|
row_color:
|
46
|
-
with:
|
46
|
+
with: bold_white
|
47
|
+
bottom:
|
48
|
+
- format:
|
49
|
+
total:
|
50
|
+
numeric:
|
51
|
+
positive: "%.2f"
|
52
|
+
zero: "%.2f"
|
53
|
+
negative: "%.2f"
|
54
|
+
row_color:
|
55
|
+
with: bold_white
|
data/examples/license_box.rb
CHANGED
@@ -25,17 +25,48 @@ require_relative '../lib/yummi'
|
|
25
25
|
|
26
26
|
@box = Yummi::TextBox.new
|
27
27
|
|
28
|
-
@box.width = 70
|
29
|
-
@box.
|
30
|
-
@box.
|
28
|
+
@box.style.width = 70
|
29
|
+
@box.style.align = :justify
|
30
|
+
@box.style.separator[:color] = :purple
|
31
|
+
@box.style.border[:color] = :intense_purple
|
31
32
|
|
32
33
|
opt = OptionParser::new
|
33
34
|
|
34
35
|
opt.on '--align ALIGN', 'Sets the default alignment to use' do |align|
|
35
|
-
@box.
|
36
|
+
@box.style.align = align.to_sym
|
36
37
|
end
|
37
38
|
opt.on '--width WIDTH', Integer, 'Sets the text box width' do |width|
|
38
|
-
@box.width = width
|
39
|
+
@box.style.border[:width] = width
|
40
|
+
end
|
41
|
+
opt.on '--left PATTERN', 'Sets the left line pattern' do |pattern|
|
42
|
+
@box.style.border[:left] = pattern
|
43
|
+
end
|
44
|
+
opt.on '--right PATTERN', 'Sets the right line pattern' do |pattern|
|
45
|
+
@box.style.border[:right] = pattern
|
46
|
+
end
|
47
|
+
opt.on '--top-left PATTERN', 'Sets the top left corner pattern' do |pattern|
|
48
|
+
@box.style.border[:top_left] = pattern
|
49
|
+
end
|
50
|
+
opt.on '--top-right PATTERN', 'Sets the top right corner pattern' do |pattern|
|
51
|
+
@box.style.border[:top_right] = pattern
|
52
|
+
end
|
53
|
+
opt.on '--bottom-left PATTERN', 'Sets the bottom left corner pattern' do |pattern|
|
54
|
+
@box.style.border[:bottom_left] = pattern
|
55
|
+
end
|
56
|
+
opt.on '--bottom-right PATTERN', 'Sets the bottom right corner pattern' do |pattern|
|
57
|
+
@box.style.border[:bottom_right] = pattern
|
58
|
+
end
|
59
|
+
opt.on '--top PATTERN', 'Sets the top line pattern' do |pattern|
|
60
|
+
@box.style.border[:top] = pattern
|
61
|
+
end
|
62
|
+
opt.on '--bottom PATTERN', 'Sets the bottom line pattern' do |pattern|
|
63
|
+
@box.style.border[:bottom] = pattern
|
64
|
+
end
|
65
|
+
opt.on '--border COLOR', 'Sets the border color' do |color|
|
66
|
+
@box.style.border[:color] = color
|
67
|
+
end
|
68
|
+
opt.on '--no-border', 'Hide the text box borders' do
|
69
|
+
@box.no_border
|
39
70
|
end
|
40
71
|
opt.on '--help', 'Prints this message' do
|
41
72
|
puts opt
|
@@ -56,12 +87,12 @@ opt.parse! ARGV
|
|
56
87
|
@box.line_break
|
57
88
|
@box.add 'The above copyright notice and this permission notice shall be included in all
|
58
89
|
copies or substantial portions of the Software.'
|
59
|
-
@box.separator :width => @box.width / 3, :align => :center
|
90
|
+
@box.separator :width => @box.style.width / 3, :align => :center
|
60
91
|
@box.add 'THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
61
92
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
62
93
|
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
63
94
|
BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
64
95
|
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
65
96
|
OTHER DEALINGS IN THE SOFTWARE.',
|
66
|
-
:color => :
|
97
|
+
:color => :yellow
|
67
98
|
@box.print
|
data/examples/list_files.rb
CHANGED
@@ -40,7 +40,7 @@ opt.on '--color TYPE', 'Specify the color type (zebra,file,none)' do |type|
|
|
40
40
|
case type
|
41
41
|
when 'zebra'
|
42
42
|
@table.colorize_row :using => Yummi::Colorizers.stripe(:intense_gray, :intense_white)
|
43
|
-
@table.
|
43
|
+
@table.bottom do
|
44
44
|
@table.colorize_row :with => :intense_blue
|
45
45
|
@table.format :size, :using => Yummi::Formatters.byte
|
46
46
|
end
|
@@ -48,7 +48,7 @@ opt.on '--color TYPE', 'Specify the color type (zebra,file,none)' do |type|
|
|
48
48
|
@table.colorize_row do |data| # or |data, index| if you need the index
|
49
49
|
data[:directory] ? :intense_gray : :intense_white
|
50
50
|
end
|
51
|
-
@table.
|
51
|
+
@table.bottom do
|
52
52
|
@table.colorize_row :with => :intense_blue
|
53
53
|
@table.format :size, :using => Yummi::Formatters.byte
|
54
54
|
end
|
data/examples/monitor_table.rb
CHANGED
@@ -33,32 +33,45 @@ opt = OptionParser::new
|
|
33
33
|
# formats memory info for easily reading
|
34
34
|
@table.format [:max_memory, :free_memory], :using => Yummi::Formatters.byte
|
35
35
|
|
36
|
-
@table.
|
36
|
+
@table.bottom do
|
37
37
|
@table.format [:max_memory, :free_memory], :using => Yummi::Formatters.byte
|
38
|
-
@table.colorize_row :with => :
|
38
|
+
@table.colorize_row :with => :intense_white
|
39
39
|
end
|
40
40
|
|
41
41
|
# colorizer for memory
|
42
|
-
memory_colorizer = Yummi::Colorizers.percentage :max => :max_memory, :free => :free_memory
|
42
|
+
@memory_colorizer = Yummi::Colorizers.percentage :max => :max_memory, :free => :free_memory
|
43
43
|
|
44
44
|
# colorizer for threads
|
45
|
-
thread_colorizer = Yummi::Colorizers.percentage :max => :max_threads,
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
45
|
+
@thread_colorizer = Yummi::Colorizers.percentage :max => :max_threads,
|
46
|
+
:using => :in_use_threads,
|
47
|
+
:colors => {
|
48
|
+
:omg => :intense_red
|
49
|
+
},
|
50
|
+
:threshold => {
|
51
|
+
:warn => 0.9,
|
52
|
+
:bad => 0.5,
|
53
|
+
:omg => 0.3
|
54
|
+
}
|
55
|
+
|
56
|
+
def zebra_colors
|
57
|
+
@table.colorize_row :using => Yummi::Colorizers.stripe(:yellow, :purple)
|
58
|
+
end
|
59
|
+
|
60
|
+
def full_colors
|
61
|
+
@table.colorize :server_name, :with => :purple
|
62
|
+
@table.colorize :free_memory, :using => @memory_colorizer
|
63
|
+
@table.colorize :in_use_threads, :using => @thread_colorizer
|
64
|
+
@table.colorize [:max_memory, :max_threads], :with => :gray
|
65
|
+
end
|
66
|
+
|
67
|
+
full_colors
|
68
|
+
|
69
|
+
opt.on '--color TYPE', 'Specify the color type (zebra,full,none)' do |type|
|
53
70
|
case type
|
54
71
|
when 'zebra'
|
55
|
-
|
56
|
-
when '
|
57
|
-
|
58
|
-
@table.using_row do
|
59
|
-
@table.colorize :free_memory, :using => memory_colorizer
|
60
|
-
@table.colorize :in_use_threads, :using => thread_colorizer
|
61
|
-
end
|
72
|
+
zebra_colors
|
73
|
+
when 'full'
|
74
|
+
full_colors
|
62
75
|
when 'none'
|
63
76
|
@table.no_colors
|
64
77
|
else
|
@@ -88,7 +101,7 @@ opt.parse ARGV
|
|
88
101
|
['Server 1', 1_000_000_000, 750_000_000, 200, 170],
|
89
102
|
['Server 2', 1_000_000_000, 700_000_000, 200, 180],
|
90
103
|
['Server 3', 1_000_000_000, 50_000_000, 200, 50],
|
91
|
-
['Server 4', 1_000_000_000, 200_000_000, 200,
|
104
|
+
['Server 4', 1_000_000_000, 200_000_000, 200, 100],
|
92
105
|
['Server 5', 1_000_000_000, 5_000_000, 200, 50],
|
93
106
|
['Server 6', 1_000_000_000, 750_000_000, 200, 50],
|
94
107
|
]
|
@@ -99,11 +112,25 @@ opt.parse ARGV
|
|
99
112
|
:max_threads => 200,
|
100
113
|
:in_use_threads => 170
|
101
114
|
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
115
|
+
class ServerStatus
|
116
|
+
attr_reader :server_name, :max_memory, :free_memory, :max_threads, :in_use_threads
|
117
|
+
|
118
|
+
def initialize server_name, max_memory, free_memory, max_threads, in_use_threads
|
119
|
+
@server_name = server_name
|
120
|
+
@max_memory = max_memory
|
121
|
+
@free_memory = free_memory
|
122
|
+
@max_threads = max_threads
|
123
|
+
@in_use_threads = in_use_threads
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
@table.add ServerStatus::new(
|
128
|
+
'Server 8',
|
129
|
+
1_000_000_000,
|
130
|
+
5_000_000,
|
131
|
+
200,
|
132
|
+
180
|
133
|
+
)
|
107
134
|
|
108
135
|
@table.add :server_name => 'Total',
|
109
136
|
:max_memory => @table.column(:max_memory).inject(:+),
|
data/lib/yummi.rb
CHANGED
@@ -28,20 +28,19 @@ module Yummi
|
|
28
28
|
|
29
29
|
# The Color Schema Definition
|
30
30
|
module Schema
|
31
|
-
# Normal Linux Terminal Colors, used by default in normal
|
32
|
-
# highlight color types
|
31
|
+
# Normal Linux Terminal Colors, used by default in normal color types
|
33
32
|
NORMAL_COLORS = {
|
34
|
-
:colors => [:black, :red, :green, :yellow, :blue, :purple, :cyan, :gray],
|
33
|
+
:colors => [:black, :red, :green, :yellow, :blue, :purple, :cyan, [:gray, :white]],
|
35
34
|
:default => :gray
|
36
35
|
}
|
37
|
-
# Intense Linux Terminal Colors, used by default in
|
36
|
+
# Intense Linux Terminal Colors, used by default in bold color types
|
38
37
|
ALTERNATE_COLORS = {
|
39
38
|
:colors => [:gray, :red, :green, :yellow, :blue, :purple, :cyan, :white],
|
40
39
|
:default => :gray
|
41
40
|
}
|
42
41
|
end
|
43
42
|
|
44
|
-
#
|
43
|
+
# Color mappings
|
45
44
|
COLORS = {}
|
46
45
|
|
47
46
|
#
|
@@ -72,30 +71,34 @@ module Yummi
|
|
72
71
|
# (1 based) too. (:intense_red and :intense_2, for example)
|
73
72
|
#
|
74
73
|
def self.add_color_map mappings
|
75
|
-
mappings.each do |
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
74
|
+
mappings.each do |types, config|
|
75
|
+
[*types].each do |type|
|
76
|
+
schema = config[:schema]
|
77
|
+
schema[:colors].each_with_index do |colors, key_code|
|
78
|
+
[*colors].each do |color|
|
79
|
+
# maps the default color for a type
|
80
|
+
COLORS[type] = "#{config[:key_code]}#{key_code}" if color == schema[:default]
|
81
|
+
# do not use prefix if schema is default
|
82
|
+
prefix = (type == :default ? '' : "#{type}_")
|
83
|
+
# maps the color using color name
|
84
|
+
key = "#{prefix}#{color}"
|
85
|
+
COLORS[key.to_sym] = "#{config[:key_code]}#{key_code}"
|
86
|
+
# maps the color using color key code
|
87
|
+
key = "#{prefix}#{key_code + 1}"
|
88
|
+
COLORS[key.to_sym] = "#{config[:key_code]}#{key_code}"
|
89
|
+
# maps the color using color name if default schema does not defines it
|
90
|
+
# example: yellow and white are present only in strong/intense schema
|
91
|
+
COLORS[color.to_sym] = "#{config[:key_code]}#{key_code}" unless COLORS[color]
|
92
|
+
end
|
93
|
+
end
|
91
94
|
end
|
92
95
|
end
|
93
96
|
end
|
94
97
|
|
95
98
|
# Escape the given text with the given color code
|
96
99
|
def self.escape key
|
97
|
-
return key unless key and COLORS[key.to_sym]
|
98
|
-
"\e[#{COLORS[key.to_sym]}m"
|
100
|
+
return key unless key and COLORS[key.to_s.to_sym]
|
101
|
+
"\e[#{COLORS[key.to_s.to_sym]}m"
|
99
102
|
end
|
100
103
|
|
101
104
|
# Colorize the given text with the given color
|
@@ -111,37 +114,26 @@ module Yummi
|
|
111
114
|
|
112
115
|
end
|
113
116
|
|
117
|
+
#
|
118
|
+
# Colorizes the text using the given color.
|
119
|
+
#
|
120
|
+
# This method also checks if the color mode is in chain (like in "underline_bold_green").
|
121
|
+
#
|
114
122
|
# see #Color#colorize
|
115
|
-
def self.colorize string, color
|
116
|
-
Color.colorize string, color
|
117
|
-
end
|
118
|
-
|
119
|
-
#
|
120
|
-
# A module to handle blocks by dynamically resolving parameters
|
121
|
-
#
|
122
|
-
# see #DataEvalColorizer
|
123
123
|
#
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
# context = :max => 10, :curr => 5, ratio => 0.15
|
133
|
-
# percentage = BlockHandler.call_block(context) { |max,curr| curr.to_f / max }
|
134
|
-
#
|
135
|
-
def block_call (context, &block)
|
136
|
-
args = []
|
137
|
-
block.parameters.each do |parameter|
|
138
|
-
args << context[parameter[1]]
|
124
|
+
def self.colorize string, color
|
125
|
+
#check if there is more than one color classifier
|
126
|
+
modes = color.to_s.split(/_/)
|
127
|
+
if modes.size >= 3
|
128
|
+
color = modes.last
|
129
|
+
modes.delete_at(-1)
|
130
|
+
modes.each do |mode|
|
131
|
+
string = Color.colorize(string, "#{mode}_#{color}")
|
139
132
|
end
|
140
|
-
|
133
|
+
string
|
134
|
+
else
|
135
|
+
Color.colorize string, color
|
141
136
|
end
|
142
|
-
|
143
|
-
module_function :block_call
|
144
|
-
|
145
137
|
end
|
146
138
|
|
147
139
|
# A module to align texts based on a reference width
|
@@ -191,7 +183,9 @@ module Yummi
|
|
191
183
|
extra_spaces = width - text.size
|
192
184
|
return text unless extra_spaces > 0
|
193
185
|
words = text.split ' '
|
186
|
+
# do not justify only one word
|
194
187
|
return text if words.size == 1
|
188
|
+
# do not justify few words
|
195
189
|
return text if extra_spaces / (words.size - 1) > 2
|
196
190
|
until extra_spaces == 0
|
197
191
|
words.each_index do |i|
|
@@ -206,6 +200,46 @@ module Yummi
|
|
206
200
|
|
207
201
|
end
|
208
202
|
|
203
|
+
#
|
204
|
+
# A module to handle blocks by dynamically resolving parameters
|
205
|
+
#
|
206
|
+
# see #DataEvalColorizer
|
207
|
+
#
|
208
|
+
module BlockHandler
|
209
|
+
|
210
|
+
#
|
211
|
+
# Calls the block resolving the parameters by getting the parameter name from the
|
212
|
+
# given context.
|
213
|
+
#
|
214
|
+
# === Example
|
215
|
+
#
|
216
|
+
# context = :max => 10, :curr => 5, ratio => 0.15
|
217
|
+
# percentage = BlockHandler.call_block(context) { |max,curr| curr.to_f / max }
|
218
|
+
#
|
219
|
+
def block_call (context, &block)
|
220
|
+
args = []
|
221
|
+
block.parameters.each do |parameter|
|
222
|
+
args << context[parameter[1]]
|
223
|
+
end
|
224
|
+
block.call(*args)
|
225
|
+
end
|
226
|
+
|
227
|
+
module_function :block_call
|
228
|
+
|
229
|
+
end
|
230
|
+
|
231
|
+
class Context
|
232
|
+
attr_reader :value, :obj
|
233
|
+
|
234
|
+
def initialize (value)
|
235
|
+
@value = value
|
236
|
+
end
|
237
|
+
|
238
|
+
def [] (index)
|
239
|
+
obj[index]
|
240
|
+
end
|
241
|
+
end
|
242
|
+
|
209
243
|
# A class to expose indexed data by numeric indexes and aliases.
|
210
244
|
class IndexedData
|
211
245
|
|