Class: Console::Mux::ColorFormatter
- Defined in:
- lib/console/mux/color_formatter.rb
Constant Summary collapse
- BASIC_COLORS =
{ :black => 0, :red => 1, :green => 2, :yellow => 3, :blue => 4, :magenta => 5, :cyan => 6, :grey => 7, }
- N_COLORS =
On 256 color term, many colors beyond 127 seem to be unreadably light. Of course, if your terminal has a dark background that may be preferable.
[127, `tput colors`.to_i].min
- COLOR_STRINGS =
[]
- RESET_COLORS =
last string is reset
`tput sgr0`
- MAX_WIDTH =
35
- MIN_WIDTH =
8
Instance Attribute Summary collapse
-
#label_width ⇒ Object
Returns the value of attribute label_width.
Instance Method Summary collapse
- #format(event) ⇒ Object
-
#initialize(hash = {}) ⇒ ColorFormatter
constructor
A new instance of ColorFormatter.
Constructor Details
#initialize(hash = {}) ⇒ ColorFormatter
Returns a new instance of ColorFormatter.
68 69 70 71 72 |
# File 'lib/console/mux/color_formatter.rb', line 68 def initialize(hash={}) super(hash) @label_width = MIN_WIDTH @colors = Hash.new end |
Instance Attribute Details
#label_width ⇒ Object
Returns the value of attribute label_width.
66 67 68 |
# File 'lib/console/mux/color_formatter.rb', line 66 def label_width @label_width end |
Instance Method Details
#format(event) ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/console/mux/color_formatter.rb', line 74 def format(event) self.label_width = [[self.label_width, event.name.size].max, MAX_WIDTH].min color, name = case event.name when 'process' [:red, '-' * label_width] else [color_for(event.name), event.name] end "%s%-#{label_width}s|%s %s" % [set_color_str(color), name, unset_color_str, event.data] end |