Sha256: 3e634d1efe6c65f66c6b2bba1e78a8d399d6e7d7d3bca8700de8447f38d536ed

Contents?: true

Size: 1.22 KB

Versions: 6

Compression:

Stored size: 1.22 KB

Contents

# Author::    Nicolas Pouillard  <ertai@lrde.epita.fr>.
# Copyright:: Copyright (c) 2005 Uttk Team. All rights reserved.
# License::   LGPL
# Revision::  $Id: /w/fey/uttk/trunk/lib/uttk/path_filters/ColorStatus.rb 21844 2006-02-17T17:26:59.771162Z pouillar  $

class StyledString < String
  def to_yaml ( opts={} )
    to_s
  end
  def to_s
    self
  end
end

module Uttk

  module PathFilters

    class ColorStatus < PathFilter
      include Concrete

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

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

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

      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

    end # class ColorStatus

  end # module PathFilters

end # module Uttk

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
uttk-0.3.1.2 lib/uttk/path_filters/ColorStatus.rb
uttk-0.3.5.0 lib/uttk/path_filters/ColorStatus.rb
uttk-0.3.6.1 lib/uttk/path_filters/ColorStatus.rb
uttk-0.4.6.1 lib/uttk/path_filters/ColorStatus.rb
uttk-0.4.6.2 lib/uttk/path_filters/ColorStatus.rb
uttk-0.4.5.0 lib/uttk/path_filters/ColorStatus.rb