Class: Console::Mux::ColorFormatter

Inherits:
Log4r::BasicFormatter
  • Object
show all
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

Instance Method Summary collapse

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_widthObject

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