Class: Uttk::PathFilters::ColorStatus

Inherits:
PathFilter show all
Includes:
Concrete
Defined in:
lib/uttk/path_filters/ColorStatus.rb

Constant Summary collapse

STYLE =
{
  :PASS  => [:green],
  :FAIL  => [:red],
  :ABORT => [:magenta],
  :SKIP  => [:yellow],
  :ERROR => [:bold, :red]
}

Instance Method Summary collapse

Methods inherited from PathFilter

#update

Methods inherited from Filters::Filter

composition, #notif

Methods inherited from Logger::Backend

#update

Constructor Details

#initialize(*a, &b) ⇒ ColorStatus

Returns a new instance of ColorStatus.



22
23
24
25
26
# File 'lib/uttk/path_filters/ColorStatus.rb', line 22

def initialize ( *a, &b )
  raise "HighLine is unavailable" unless defined? HighLine
  @h = HighLine.new
  super
end

Instance Method Details

#color(str) ⇒ Object



38
39
40
41
42
43
44
# File 'lib/uttk/path_filters/ColorStatus.rb', line 38

def color ( str )
  if str =~ /^([A-Z]+)(\(.*\))?$/
    node = StyledString.new(@h.color(str, *STYLE[$1.to_sym]).to_s)
  else
    str
  end
end

#filter(path, leaf) ⇒ Object



46
47
48
49
50
51
# File 'lib/uttk/path_filters/ColorStatus.rb', line 46

def filter ( path, leaf )
  if (leaf.is_a? Symbol or leaf.is_a? String) and not leaf.to_s.empty?
    leaf = color(leaf.to_s)
  end
  [path, leaf]
end