yummi 0.8.1 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md CHANGED
@@ -1,6 +1,7 @@
1
1
  # Yummi
2
2
 
3
- This is a tool to colorize your console app.
3
+ This is a tool to make your console app more tasty. Yummi provides a set of console line elements
4
+ also with a delegator for colorizing Strings using the awesome gem term-ansicolor.
4
5
 
5
6
  ## Installation
6
7
 
@@ -46,7 +47,7 @@ Example:
46
47
  patterns:
47
48
  TRACE : cyan
48
49
  DEBUG : blue
49
- INFO : gray
50
+ INFO : black
50
51
  WARN : yellow
51
52
  ERROR : red
52
53
  FATAL : intense_red
data/bin/yummi CHANGED
@@ -27,20 +27,10 @@ require 'optparse'
27
27
 
28
28
  @params = []
29
29
 
30
- def get_input message, default
31
- puts(message.colorize(:blue) << ": " << " [#{default}]".colorize(:yellow))
32
- input = gets.chomp
33
- return default if input.empty?
34
- input
35
- end
36
-
37
30
  opt = OptionParser::new
38
31
  opt.on '-c COLOR', '--color=COLOR', 'Colorize using the given color' do |color|
39
32
  @color = color
40
33
  end
41
- opt.on '-s STYLE', '--style=STYLE', Array, 'Sets the styles to use (bold, highlight, underline, blink, ...)' do |styles|
42
- @styles = styles
43
- end
44
34
  opt.on '-f FORMAT', '--format=FORMAT', 'Sets the format to use (a "%s" means the colorized message)' do |format|
45
35
  @format = format
46
36
  end
@@ -67,27 +57,6 @@ opt.on '-l FILES', '--load=FILES', Array, 'Include the files for extending compo
67
57
  load File.expand_path(file)
68
58
  end
69
59
  end
70
- opt.on '--shell-script', 'Outputs a shell script program to colorize texts without a ruby environment' do
71
- abort "Environment not supported" unless Yummi::Color::supported?
72
-
73
- generator = Yummi::Generator::ShellScript::new
74
- puts generator.generate
75
- exit 0
76
- end
77
- opt.on '--install', 'Installs a shell script program to colorize texts without a ruby environment' do
78
- abort "Environment not supported" unless Yummi::Color::supported?
79
-
80
- puts ".: Yummi shell script installation :.".colorize(:bold_yellow)
81
- name = get_input "Program name", "colorize"
82
- location = File.expand_path(get_input("Install location", "~/bin"))
83
- file = File.join(location, name)
84
-
85
- generator = Yummi::Generator::ShellScript::new
86
- generator.install file
87
-
88
- puts "Program installed!".colorize(:bold_green)
89
- exit 0
90
- end
91
60
  opt.on '-h', '--help', 'Display this help message' do
92
61
  puts opt
93
62
  exit 0
@@ -102,7 +71,7 @@ opt.parse! ARGV
102
71
 
103
72
  def print_out message
104
73
  output_text = if @color
105
- Yummi::colorize message, @color, @styles
74
+ Yummi::colorize message, @color
106
75
  elsif @colorizer
107
76
  @colorizer.colorize message
108
77
  end
@@ -129,6 +98,6 @@ else
129
98
  print_out line.chomp
130
99
  end
131
100
  rescue Interrupt
132
- puts Yummi::colorize("Aborted!", :red)
101
+ puts "Aborted!".red
133
102
  end
134
103
  end
@@ -18,9 +18,9 @@ format:
18
18
  with: none
19
19
  color:
20
20
  description:
21
- with: purple
21
+ with: magenta
22
22
  authentication_code:
23
- with: highlight_gray
23
+ with: black.on_intense_white
24
24
  eletronic:
25
25
  boolean:
26
26
  if_true: blue
@@ -28,7 +28,7 @@ color:
28
28
  value,total:
29
29
  numeric:
30
30
  positive: green
31
- zero: gray
31
+ zero: white
32
32
  negative: red
33
33
  undefined:
34
34
  with: red
@@ -43,7 +43,7 @@ top:
43
43
  zero: "%.2f"
44
44
  negative: "%.2f"
45
45
  row_color:
46
- with: bold_white
46
+ with: intense_white
47
47
  bottom:
48
48
  - format:
49
49
  total:
@@ -52,4 +52,4 @@ bottom:
52
52
  zero: "%.2f"
53
53
  negative: "%.2f"
54
54
  row_color:
55
- with: bold_white
55
+ with: intense_white
@@ -27,8 +27,8 @@ require_relative '../lib/yummi'
27
27
 
28
28
  @box.style.width = 70
29
29
  @box.style.align = :justify
30
- @box.style.separator[:color] = :purple
31
- @box.style.border[:color] = :intense_purple
30
+ @box.style.separator[:color] = :magenta
31
+ @box.style.border[:color] = :intense_magenta
32
32
 
33
33
  opt = OptionParser::new
34
34
 
@@ -39,14 +39,14 @@ opt = OptionParser::new
39
39
  opt.on '--color TYPE', 'Specify the color type (zebra,file,none)' do |type|
40
40
  case type
41
41
  when 'zebra'
42
- @table.colorize_row :using => Yummi::Colorizers.stripe(:intense_gray, :intense_white)
42
+ @table.colorize_row :using => Yummi::Colorizers.stripe(:intense_black, :intense_white)
43
43
  @table.bottom do
44
44
  @table.colorize_row :with => :intense_blue
45
45
  @table.format :size, :using => Yummi::Formatters.byte
46
46
  end
47
47
  when 'file'
48
48
  @table.colorize_row do |data| # or |data, index| if you need the index
49
- data[:directory] ? :intense_gray : :intense_white
49
+ data[:directory] ? :intense_black : :intense_white
50
50
  end
51
51
  @table.bottom do
52
52
  @table.colorize_row :with => :intense_blue
@@ -43,7 +43,7 @@ colorizer = Yummi::Colorizers.pattern :prefix => /\[/,
43
43
  'FATAL' => :intense_red,
44
44
  'WARN' => :yellow,
45
45
  'INFO' => :green,
46
- 'DEBUG' => :gray
46
+ 'DEBUG' => :black
47
47
  }
48
48
 
49
49
  log.each_line do |line|
@@ -54,14 +54,14 @@ end
54
54
  }
55
55
 
56
56
  def zebra_colors
57
- @table.colorize_row :using => Yummi::Colorizers.stripe(:yellow, :purple)
57
+ @table.colorize_row :using => Yummi::Colorizers.stripe(:yellow, :magenta)
58
58
  end
59
59
 
60
60
  def full_colors
61
- @table.colorize :server_name, :with => :purple
61
+ @table.colorize :server_name, :with => :magenta
62
62
  @table.colorize :free_memory, :using => @memory_colorizer
63
63
  @table.colorize :in_use_threads, :using => @thread_colorizer
64
- @table.colorize [:max_memory, :max_threads], :with => :gray
64
+ @table.colorize [:max_memory, :max_threads], :with => :black
65
65
  end
66
66
 
67
67
  full_colors
data/lib/yummi.rb CHANGED
@@ -20,142 +20,47 @@
20
20
  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
21
  # THE SOFTWARE.
22
22
 
23
+ require 'set'
24
+ require 'term/ansicolor'
23
25
  require_relative "yummi/version"
24
26
 
25
27
  module Yummi
26
- # Base for colorizing
27
- module Color
28
-
29
- # The Color Schema Definition
30
- module Schema
31
- # Normal Linux Terminal Colors, used by default in normal color types
32
- NORMAL_COLORS = {
33
- :colors => [:black, :red, :green, [:yellow, :orange], :blue, [:purple, :magenta], :cyan, [:gray, :white]],
34
- :default => :white
35
- }
36
- # Intense Linux Terminal Colors, used by default in bold color types
37
- ALTERNATE_COLORS = {
38
- :colors => [:gray, :red, :green, :yellow, :blue, [:purple, :magenta], :cyan, :white],
39
- :default => :gray
40
- }
41
- end
42
-
43
- # Color mappings
44
- COLORS = {}
45
-
46
- #
47
- # Checks if the environment is supported by Yummi.
48
- #
49
- # Currently (known) unsupported environments are:
50
- # * Windows
51
- #
52
- def self.supported?
53
- not RUBY_PLATFORM['mingw'] #Windows
54
- end
55
-
56
- #
57
- # Clears all color mappings and add this ones
58
- #
59
- # see #add_color_map
60
- #
61
- def self.load_color_map mappings
62
- COLORS.clear
63
- add_color_map mappings
64
- end
65
-
66
- #
67
- # Adds the given color mappings, overriding the already defined.
68
- #
69
- # Colors are printed using a "[#{type_key_code}:3#{color_key_code}m" prefix.
70
- #
71
- # === Args
72
- #
73
- # The mappings is a Hash of Hashes, each parent hash must define a type key and the
74
- # child hash must contain the following keys:
75
- #
76
- # +key_code+::
77
- # The key code to map this type. If the type name is :default, the mapping will not
78
- # use the name "default" (:normal_red will become only :red)
79
- # +schema+::
80
- # An array with the color names. Each name will be mapped and their positions
81
- # (1 based) too. (:intense_red and :intense_2, for example)
82
- #
83
- def self.add_color_map mappings
84
- mappings.each do |types, config|
85
- [*types].each do |type|
86
- schema = config[:schema]
87
- schema[:colors].each_with_index do |colors, key_code|
88
- [*colors].each do |color|
89
- # maps the default color for a type
90
- COLORS[type] = "#{config[:key_code]}#{key_code}" if color == schema[:default]
91
- # do not use prefix if schema is default
92
- prefix = (type == :default ? '' : "#{type}_")
93
- # maps the color using color name
94
- key = "#{prefix}#{color}"
95
- COLORS[key.to_sym] = "#{config[:key_code]}#{key_code}"
96
- # maps the color using color key code
97
- key = "#{prefix}#{key_code + 1}"
98
- COLORS[key.to_sym] = "#{config[:key_code]}#{key_code}"
99
- # maps the color using color name if default schema does not defines it
100
- # example: yellow and white are present only in strong/intense schema
101
- COLORS[color.to_sym] = "#{config[:key_code]}#{key_code}" unless COLORS[color]
102
- end
103
- end
104
- end
105
- end
106
- end
107
-
108
- # Escape the given text with the given color code
109
- def self.escape key
110
- return key unless key and COLORS[key.to_sym]
111
- "\e[#{COLORS[key.to_sym]}m"
112
- end
113
-
114
- # Colorize the given text with the given color
115
- def self.colorize string, color
116
- return string if color.to_s == 'none'
117
- color, end_color = [color, "\e[0;0m"].map { |key| Color.escape(key) }
118
- color ? "#{color}#{string}#{end_color}" : string
119
- end
120
28
 
29
+ #
30
+ # Checks if the environment is supported by Yummi.
31
+ #
32
+ # Currently (known) unsupported environments are:
33
+ # * Windows
34
+ #
35
+ def self.supported?
36
+ not RUBY_PLATFORM['mingw'] #Windows
121
37
  end
122
38
 
123
- #
124
- # Colorizes the text using the given color.
125
- #
126
- # Examples:
127
39
  #
128
- # Yummi.colorize "message", :red # produces a red text
129
- # Yummi.colorize "message", :bold_red # produces a bold (intensive) red text
130
- # Yummi.colorize "message", :red , :bold # produces a red text
40
+ # Colorizes the given string with the given color
41
+ #
42
+ # The color may be an integer, a string or a dot
43
+ # separated color style (ex: "bold.yellow" or
44
+ # "underline.bold.green").
131
45
  #
132
- # see #Color#colorize
46
+ # Since this method delegates to Term::ANSIColor,
47
+ # the given color should be compatible with it.
133
48
  #
134
- def self.colorize string, color, styles = []
135
- styles ||= [] # prevents nil arguments
136
- #check if there is more than one color classifier
137
- if styles.empty?
138
- styles = color.to_s.split(/_/)
139
- color = styles.last
140
- styles.delete_at(-1)
141
- end
142
- unless styles.empty?
143
- [*styles].each do |style|
144
- string = Color.colorize(string, "#{style}_#{color}")
145
- end
146
- string
49
+ def self.colorize string, color
50
+ return string unless color
51
+ if color.is_a? Fixnum
52
+ string.color color
53
+ elsif color.match(/\./)
54
+ result = string
55
+ color.to_s.split(/\./).each { |c| result = colorize(result, c) }
56
+ result
57
+ elsif color.match(/\d+/)
58
+ string.color color.to_i
147
59
  else
148
- Color.colorize string, color
60
+ string.send color
149
61
  end
150
62
  end
151
63
 
152
- #
153
- # Extracts the text from a colorized string
154
- #
155
- def self.uncolorize string
156
- string.gsub(/\e\[\d;\d{2}m/, '').gsub(/\e\[0;0m/, '')
157
- end
158
-
159
64
  # A module to align texts based on a reference width
160
65
  module Aligner
161
66
 
@@ -323,7 +228,7 @@ module Yummi
323
228
 
324
229
  def self.load_resource name, params = {:from => ''}
325
230
  file = File.expand_path name.to_s
326
- if File.exist? file
231
+ if File.file? file
327
232
  return YAML::load_file(file)
328
233
  else
329
234
  from = params[:from].to_s
@@ -357,18 +262,16 @@ module Yummi
357
262
 
358
263
  end
359
264
 
360
- require_relative 'yummi/no_colors' unless Yummi::Color::supported?
265
+ require_relative 'yummi/no_colors' unless Yummi::supported?
361
266
 
362
267
  require_relative 'yummi/extensions'
363
268
  require_relative 'yummi/data_parser'
364
269
  require_relative "yummi/colorizers"
365
270
  require_relative "yummi/formatters"
366
- require_relative 'yummi/color_mapping'
367
271
  require_relative 'yummi/table'
368
272
  require_relative 'yummi/table_builder'
369
273
  require_relative 'yummi/text_box'
370
274
  require_relative 'yummi/logger'
371
- require_relative 'yummi/generator'
372
275
 
373
276
  # if the output is being piped, turn off the colors
374
277
  unless $stdout.isatty
@@ -326,6 +326,7 @@ module Yummi
326
326
  # Creates a new colorizer using the given colors
327
327
  def initialize (*colors)
328
328
  @colors = colors.flatten
329
+ @colors = [nil] if @colors.empty?
329
330
  @count = -1
330
331
  end
331
332
 
@@ -21,11 +21,16 @@
21
21
  # THE SOFTWARE.
22
22
 
23
23
  class String
24
+ include Term::ANSIColor
24
25
 
25
- def uncolorize
26
- Yummi::uncolorize self
27
- end
28
-
26
+ #
27
+ # Colorizes the string using #Yummi#colorize
28
+ #
29
+ # If params is a hash, the keys will be used as a regexp and the
30
+ # result of #gsub will be colorized using the value color.
31
+ #
32
+ # Otherwise, the params will be sended to Yummi#colorize
33
+ #
29
34
  def colorize params
30
35
  if params.is_a? Hash
31
36
  text = self
@@ -37,4 +42,43 @@ class String
37
42
  Yummi::colorize self, params
38
43
  end
39
44
 
45
+ #
46
+ # Returns the string wrapped in a #Yummi#TextBox. The given parameters will be used
47
+ # to instantiate the TextBox.
48
+ #
49
+ def on_box params = {}
50
+ box = Yummi::TextBox::new params
51
+ box.add self
52
+ return box
53
+ end
54
+
55
+ end
56
+
57
+ class Array
58
+
59
+ #
60
+ # Colorizes each array item in a new String array
61
+ #
62
+ def colorize params
63
+ map {|n| n.to_s.colorize params}
64
+ end
65
+
66
+ #
67
+ # Returns a new array using the items with no color applied
68
+ #
69
+ def uncolored
70
+ map {|n| n.to_s.uncolored}
71
+ end
72
+
73
+ #
74
+ # Returns a #Yummi#Table using the array content as the data.
75
+ #
76
+ # The parameters will be used to instantiate the table.
77
+ #
78
+ def on_table params = {}
79
+ table = Yummi::Table::new params
80
+ table.data = self
81
+ return table
82
+ end
83
+
40
84
  end
data/lib/yummi/logger.rb CHANGED
@@ -51,7 +51,7 @@ module Yummi
51
51
  # * +WARN+: yellow
52
52
  # * +ERROR+: red
53
53
  # * +FATAL+: red (intense)
54
- # * +ANY+: gray (intense)
54
+ # * +ANY+: black (intense)
55
55
  #
56
56
  # If a block is passed, it will be used to format the message. The block can use
57
57
  # the following variables: severity, time, program_name and message.
@@ -63,7 +63,7 @@ module Yummi
63
63
  :warn => :yellow,
64
64
  :error => :red,
65
65
  :fatal => :intense_red,
66
- :any => :intense_gray
66
+ :any => :intense_black
67
67
  }.merge! colors
68
68
  @format_block = block
69
69
  end
@@ -72,7 +72,7 @@ module Yummi
72
72
 
73
73
  def call(severity, time, program_name, message)
74
74
  color = @colors[severity.downcase.to_sym]
75
- Yummi::Color.colorize output(severity, time, program_name, message), color
75
+ Yummi::colorize output(severity, time, program_name, message), color
76
76
  end
77
77
 
78
78
  # Formats the message, override this method instead of #call
@@ -20,14 +20,4 @@
20
20
  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
21
  # THE SOFTWARE.
22
22
 
23
- module Yummi
24
-
25
- module Color
26
-
27
- def self.colorize(str, color)
28
- str
29
- end
30
-
31
- end
32
-
33
- end
23
+ Term::ANSIColor::coloring = false
@@ -5,4 +5,4 @@ patterns:
5
5
  INFO : white
6
6
  WARN : yellow
7
7
  ERROR : red
8
- FATAL : intense_red
8
+ FATAL : bold.red
@@ -8,4 +8,4 @@ patterns:
8
8
  NOTIFICATION : yellow
9
9
  ERROR : red
10
10
  SEVERE : red
11
- FATAL : intense_red
11
+ FATAL : bold.red
@@ -1,12 +1,12 @@
1
1
  prefix: '####<[^>]+>\s<'
2
2
  suffix: '>'
3
3
  patterns:
4
- Trace : purple
4
+ Trace : magenta
5
5
  Debug : blue
6
6
  Info : white
7
7
  Notice : cyan
8
8
  Warning : yellow
9
9
  Error : red
10
- Critical : intense_red
11
- Alert : intense_red
12
- Emergency : intense_red
10
+ Critical : bold.red
11
+ Alert : bold.red
12
+ Emergency : bold.red
data/lib/yummi/table.rb CHANGED
@@ -20,6 +20,8 @@
20
20
  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
21
  # THE SOFTWARE.
22
22
 
23
+ require 'ostruct'
24
+
23
25
  module Yummi
24
26
  # A Table that supports colorizing title, header, values and also formatting the values.
25
27
  class Table
@@ -47,28 +49,39 @@ module Yummi
47
49
  # The table header
48
50
  attr_reader :header
49
51
 
50
- # Creates a new table with the default attributes:
51
- #
52
- # * Title color: intense_yellow
53
- # * Header color: intense_blue
54
- # * Values color: none
55
- # * Colspan: 2
56
- # * Default Align: right and first element to left
57
- def initialize
52
+ #
53
+ # Creates a new table. A hash containing the style properties may be given to override
54
+ # the defaults.
55
+ #
56
+ # * Title (title): none
57
+ # * Description (description): none
58
+ # * Header (header): none
59
+ #
60
+ # Hash in "style" key:
61
+ #
62
+ # * Title color (title): bold.yellow
63
+ # * Header color (header): bold.blue
64
+ # * Values color (color): none
65
+ # * Colspan (colspan): 2
66
+ # * Default Align (align): right and first element to left
67
+ #
68
+ def initialize params = {}
69
+ params = OpenStruct::new params
70
+ params.style ||= {}
58
71
  @data = []
59
72
  @header = []
60
- @title = nil
61
- @description = nil
73
+ @title = (params.title or nil)
74
+ @description = (params.description or nil)
62
75
  @style = {
63
- :title => :intense_yellow,
64
- :description => :intense_gray,
65
- :header => :intense_blue,
66
- :value => nil
76
+ :title => (params.style[:title] or "bold.yellow"),
77
+ :description => (params.style[:description] or "bold.black"),
78
+ :header => (params.style[:header] or "bold.blue"),
79
+ :value => (params.style[:color] or nil)
67
80
  }
68
81
 
69
- @colspan = 2
70
- @layout = :horizontal
71
- @default_align = :right
82
+ @colspan = (params.colspan or 2)
83
+ @layout = (params.layout or :horizontal)
84
+ @default_align = (params.align or :right)
72
85
  @aliases = []
73
86
 
74
87
  @align = [:left]
@@ -76,6 +89,8 @@ module Yummi
76
89
  @contexts = [:default]
77
90
  _define_ :default
78
91
  @current_context = :default
92
+
93
+ self.header = params.header if params.header
79
94
  end
80
95
 
81
96
  # Indicates that the table should not use colors.
@@ -256,7 +271,7 @@ module Yummi
256
271
  #
257
272
  # === Example
258
273
  #
259
- # table.colorize :description, :with => :purple
274
+ # table.colorize :description, :with => :magenta
260
275
  # table.colorize([:value, :total]) { |value| :red if value < 0 }
261
276
  #
262
277
  def colorize (indexes, params = {}, &block)
@@ -355,8 +370,8 @@ module Yummi
355
370
  data_output = build_data_output
356
371
 
357
372
  string = ""
358
- string << Color.colorize(@title, @style[:title]) << $/ if @title
359
- string << Color.colorize(@description, @style[:description]) << $/ if @description
373
+ string << Yummi.colorize(@title, @style[:title]) << $/ if @title
374
+ string << Yummi.colorize(@description, @style[:description]) << $/ if @description
360
375
  table_data = header_output + data_output
361
376
  if @layout == :vertical
362
377
  # don't use array transpose because the data may differ in each line size
@@ -365,6 +380,18 @@ module Yummi
365
380
  string << content(table_data)
366
381
  end
367
382
 
383
+ #
384
+ # Calculates the table width using the rendered lines
385
+ #
386
+ def width
387
+ string = to_s
388
+ max_width = 0
389
+ string.each_line do |line|
390
+ max_width = [max_width, line.uncolored.chomp.size].max
391
+ end
392
+ max_width
393
+ end
394
+
368
395
  private
369
396
 
370
397
  def extract_component params, &block
@@ -31,34 +31,48 @@ module Yummi
31
31
  #
32
32
  # Holds the style information for this box. Supported properties are:
33
33
  #
34
- # width: the box width (default: none)
34
+ # width: the box width (default: bold.black)
35
35
  # align: the default alignment to use (default: left)
36
36
  # separator: the style for separators, defined as a hash
37
- # color: separator color (default: none)
37
+ # color: separator color (default: bold.black)
38
38
  # pattern: separator pattern (default: '-')
39
39
  # width: separator width (default: box width)
40
40
  #
41
41
  attr_reader :style
42
42
 
43
- def initialize
44
- @color = :white
43
+ #
44
+ # Initializes a text box using the parameters to define the style
45
+ #
46
+ # Example:
47
+ #
48
+ # TextBox::new :align => :center, :border => {:color => :red}, :separator => {:color => :green}
49
+ #
50
+ def initialize params = {}
51
+ params = OpenStruct::new params
52
+ params.separator ||= {}
53
+ params.border ||= {}
45
54
  @content = []
46
55
  @style = OpenStruct::new
56
+
57
+ @style.width = (params.width or nil)
58
+ @style.align = (params.align or :left)
59
+
47
60
  @style.separator = {}
48
- @style.separator[:pattern] = '-'
49
- @style.separator[:width] = nil
50
- @style.separator[:align] = :left
61
+ @style.separator[:pattern] = (params.separator[:pattern] or '-')
62
+ @style.separator[:width] = (params.separator[:width] or nil)
63
+ @style.separator[:color] = (params.separator[:color] or "bold.black")
64
+ @style.separator[:align] = (params.separator[:align] or :left)
51
65
 
52
66
  @style.border = {}
53
- @style.border[:color] = nil
54
- @style.border[:top] = '-'
55
- @style.border[:bottom] = '-'
56
- @style.border[:left] = '|'
57
- @style.border[:right] = '|'
58
- @style.border[:top_left] = '+'
59
- @style.border[:top_right] = '+'
60
- @style.border[:bottom_left] = '+'
61
- @style.border[:bottom_right] = '+'
67
+ @style.border[:color] = (params.border[:color] or "bold.black")
68
+ @style.border[:top] = (params.border[:top] or '-')
69
+ @style.border[:bottom] = (params.border[:bottom] or '-')
70
+ @style.border[:left] = (params.border[:left] or '|')
71
+ @style.border[:right] = (params.border[:right] or '|')
72
+ @style.border[:top_left] = (params.border[:top_left] or '+')
73
+ @style.border[:top_right] = (params.border[:top_right] or '+')
74
+ @style.border[:bottom_left] = (params.border[:bottom_left] or '+')
75
+ @style.border[:bottom_right] = (params.border[:bottom_right] or '+')
62
76
  end
63
77
 
64
78
  def no_border
@@ -77,6 +91,7 @@ module Yummi
77
91
  # color: the text color (see #Yummi#COLORS)
78
92
  # width: the text maximum width. Set this to break the lines automatically.
79
93
  # If the #width is set, this will override the box width for this lines.
94
+ # raw: if true, the entire text will be used as one word to align the text.
80
95
  # align: the text alignment (see #Yummi#Aligner)
81
96
  #
82
97
  def add (text, params = {})
@@ -86,7 +101,8 @@ module Yummi
86
101
  }.merge! params
87
102
  if params[:width]
88
103
  width = params[:width]
89
- words = text.gsub($/, ' ').split(' ')
104
+ words = text.gsub($/, ' ').split(' ') unless params[:raw]
105
+ words ||= [text]
90
106
  buff = ''
91
107
  words.each do |word|
92
108
  # go to next line if the current word blows up the width limit
@@ -128,7 +144,7 @@ module Yummi
128
144
  # align: the separator alignment (see #Yummi#Aligner)
129
145
  #
130
146
  def separator (params = {})
131
- params = style.separator.merge! params
147
+ params = style.separator.merge params
132
148
  params[:width] ||= style.width
133
149
  raise Exception::new("Define a width for using separators") unless params[:width]
134
150
  line = fill(params[:pattern], params[:width])
@@ -151,7 +167,7 @@ module Yummi
151
167
  width = 0
152
168
  sizes = [] # the real size of each line
153
169
  content.each do |line|
154
- size = line.chomp.uncolorize.size
170
+ size = line.chomp.uncolored.size
155
171
  sizes << size
156
172
  width = [width, size].max
157
173
  end
data/lib/yummi/version.rb CHANGED
@@ -21,5 +21,5 @@
21
21
  # THE SOFTWARE.
22
22
 
23
23
  module Yummi
24
- VERSION = "0.8.1"
24
+ VERSION = "0.9.0"
25
25
  end
data/yummi.gemspec CHANGED
@@ -8,6 +8,8 @@ Gem::Specification.new do |gem|
8
8
  gem.summary = "A tool to colorize your console application."
9
9
  gem.homepage = "https://github.com/ataxexe/yummi"
10
10
 
11
+ gem.add_dependency 'term-ansicolor', '>=1.1'
12
+
11
13
  gem.files = `git ls-files`.split($\)
12
14
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
15
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
data/yummi.iml CHANGED
@@ -5,12 +5,11 @@
5
5
  <content url="file://$MODULE_DIR$">
6
6
  <sourceFolder url="file://$MODULE_DIR$/lib" isTestSource="false" />
7
7
  <sourceFolder url="file://$MODULE_DIR$/examples" isTestSource="false" />
8
- <sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
9
8
  <excludeFolder url="file://$MODULE_DIR$/pkg" />
10
9
  </content>
11
- <orderEntry type="jdk" jdkName="RVM: ruby-1.9.3-p194" jdkType="RUBY_SDK" />
10
+ <orderEntry type="inheritedJdk" />
12
11
  <orderEntry type="sourceFolder" forTests="false" />
13
- <orderEntry type="library" scope="PROVIDED" name="bundler (v1.1.4, RVM: ruby-1.9.3-p194) [gem]" level="application" />
12
+ <orderEntry type="library" scope="PROVIDED" name="bundler (v1.2.3, RVM: ruby-1.9.3-p374) [gem]" level="application" />
14
13
  </component>
15
14
  <component name="org.twodividedbyzero.idea.findbugs">
16
15
  <option name="_basePreferences">
data/yummi.ipr CHANGED
@@ -23,7 +23,11 @@
23
23
  <entry name="?*.ftl" />
24
24
  <entry name="trace.info" />
25
25
  </wildcardResourcePatterns>
26
- <annotationProcessing enabled="false" useClasspath="true" />
26
+ <annotationProcessing>
27
+ <profile default="true" name="Default" enabled="false">
28
+ <processorPath useClasspath="true" />
29
+ </profile>
30
+ </annotationProcessing>
27
31
  </component>
28
32
  <component name="CopyrightManager" default="MIT">
29
33
  <copyright>
@@ -82,6 +86,11 @@
82
86
  <option name="LOCALE" />
83
87
  <option name="OPEN_IN_BROWSER" value="true" />
84
88
  </component>
89
+ <component name="Jenkins.Application.Settings">
90
+ <option name="rssSettings">
91
+ <RssSettings />
92
+ </option>
93
+ </component>
85
94
  <component name="ModuleEditorState">
86
95
  <option name="LAST_EDITED_MODULE_NAME" />
87
96
  <option name="LAST_EDITED_TAB_NAME" />
@@ -218,7 +227,7 @@
218
227
  <component name="ProjectResources">
219
228
  <default-html-doctype>http://www.w3.org/1999/xhtml</default-html-doctype>
220
229
  </component>
221
- <component name="ProjectRootManager" version="2" languageLevel="JDK_1_5" assert-keyword="true" jdk-15="true" project-jdk-name="RVM: ruby-1.9.3-p194" project-jdk-type="RUBY_SDK">
230
+ <component name="ProjectRootManager" version="2" languageLevel="JDK_1_5" assert-keyword="true" jdk-15="true" project-jdk-name="RVM: ruby-1.9.3-p374" project-jdk-type="RUBY_SDK">
222
231
  <output url="file://$PROJECT_DIR$/out" />
223
232
  </component>
224
233
  <component name="Regex">
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yummi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.1
4
+ version: 0.9.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,8 +9,24 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-04-07 00:00:00.000000000 Z
13
- dependencies: []
12
+ date: 2013-05-10 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: term-ansicolor
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '1.1'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '1.1'
14
30
  description: A tool to colorize your console application.
15
31
  email:
16
32
  - ataxexe@gmail.com
@@ -37,13 +53,10 @@ files:
37
53
  - examples/logger.rb
38
54
  - examples/monitor_table.rb
39
55
  - lib/yummi.rb
40
- - lib/yummi/color_mapping.rb
41
56
  - lib/yummi/colorizers.rb
42
57
  - lib/yummi/data_parser.rb
43
58
  - lib/yummi/extensions.rb
44
59
  - lib/yummi/formatters.rb
45
- - lib/yummi/generate/colorize.sh.erb
46
- - lib/yummi/generator.rb
47
60
  - lib/yummi/logger.rb
48
61
  - lib/yummi/no_colors.rb
49
62
  - lib/yummi/patterns/jboss.yaml
@@ -1,48 +0,0 @@
1
- # The MIT License
2
- #
3
- # Copyright (c) 2013 Marcelo Guimarães <ataxexe@gmail.com>
4
- #
5
- # Permission is hereby granted, free of charge, to any person obtaining a copy
6
- # of this software and associated documentation files (the "Software"), to deal
7
- # in the Software without restriction, including without limitation the rights
8
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- # copies of the Software, and to permit persons to whom the Software is
10
- # furnished to do so, subject to the following conditions:
11
- #
12
- # The above copyright notice and this permission notice shall be included in
13
- # all copies or substantial portions of the Software.
14
- #
15
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- # THE SOFTWARE.
22
-
23
- Yummi::Color::load_color_map(
24
- :default => {
25
- :key_code => '0;3',
26
- :schema => Yummi::Color::Schema::NORMAL_COLORS
27
- },
28
- :reverse => {
29
- :key_code => '0;4',
30
- :schema => Yummi::Color::Schema::NORMAL_COLORS
31
- },
32
- [:intense, :strong, :bold] => {
33
- :key_code => '1;3',
34
- :schema => Yummi::Color::Schema::ALTERNATE_COLORS
35
- },
36
- [:underline, :underscore, :underscored] => {
37
- :key_code => '4;3',
38
- :schema => Yummi::Color::Schema::NORMAL_COLORS
39
- },
40
- [:blink, :blinking] => {
41
- :key_code => '5;3',
42
- :schema => Yummi::Color::Schema::NORMAL_COLORS
43
- },
44
- [:highlight, :highlighted] => {
45
- :key_code => '7;3',
46
- :schema => Yummi::Color::Schema::NORMAL_COLORS
47
- }
48
- )
@@ -1,23 +0,0 @@
1
- #!/bin/sh
2
-
3
- # .:: Generated by Yummi ::.
4
-
5
- usage() {
6
- echo "Usage: $0 COLOR TEXT [FORMAT]"
7
- echo " COLOR: a name or a number [1..8]. A modifier may also be used in a form $MOD_$COLOR"
8
- echo " TEXT: the text to colorize"
9
- echo " FORMAT: a format to use (defaults to \"%s\\n\")"
10
- exit 1
11
- }
12
- <% Yummi::Color::COLORS.each do |key, pattern| %>
13
- function color_<%= key %> {
14
- echo "<%= "$1".colorize(key) %>"
15
- }
16
- <% end %>
17
- [ "$#" = "0" ] && usage
18
-
19
- format="%s\n"
20
-
21
- [ ! -z "$3" ] && format="$3"
22
-
23
- printf "$format" $(color_"$@")
@@ -1,47 +0,0 @@
1
- # The MIT License
2
- #
3
- # Copyright (c) 2013 Marcelo Guimarães <ataxexe@gmail.com>
4
- #
5
- # Permission is hereby granted, free of charge, to any person obtaining a copy
6
- # of this software and associated documentation files (the "Software"), to deal
7
- # in the Software without restriction, including without limitation the rights
8
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- # copies of the Software, and to permit persons to whom the Software is
10
- # furnished to do so, subject to the following conditions:
11
- #
12
- # The above copyright notice and this permission notice shall be included in
13
- # all copies or substantial portions of the Software.
14
- #
15
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- # THE SOFTWARE.
22
-
23
- require 'erb'
24
-
25
- module Yummi
26
-
27
- class Generator
28
-
29
- class ShellScript
30
-
31
- def generate
32
- file = File.join(File.dirname(__FILE__), "generate/colorize.sh.erb")
33
- content = File.read(file)
34
- erb = ERB::new(content, 0, "%<>")
35
- erb.result binding
36
- end
37
-
38
- def install file
39
- File.open(file, "w") { |f| f.write generate }
40
- File.chmod(0755, file)
41
- end
42
-
43
- end
44
-
45
- end
46
-
47
- end