Module: TermColor

### Home Classes Methods

### In Files

- lib/termcolor.rb

### Namespace

- CLASS TermColor::MyListener

### Methods

- ::colorize
- ::escape
- ::parse
- ::prepare_parse
- ::tag_separate
- ::test
- ::unescape

### Included Modules

- REXML

### Files

- History.txt
- README.rdoc

### Class/Module Index

Quicksearch

- TermColor
- TermColor::MyListener
- String

No matching classes.

# TermColor

### Constants

VERSION

### Public Class Methods

colorize(text, color) click to toggle source

    # File lib/termcolor.rb, line 60
    def colorize(text, color)
      parse("<#{color}>#{escape(text)}</#{color}>")
    end

escape(text) click to toggle source

    # File lib/termcolor.rb, line 19
    def escape(text)
      escape_or_unescape(:escape, text)
    end

parse(text) click to toggle source

    # File lib/termcolor.rb, line 13
    def parse(text)
      listener = MyListener.new
      REXML::Parsers::StreamParser.new(prepare_parse(text), listener).parse
      listener.result
    end

prepare_parse(text) click to toggle source

    # File lib/termcolor.rb, line 34
    def prepare_parse(text)
      tag_separate text.gsub(/<(\/?)(\d+)>/, '<\1_\2>')
    end

tag_separate(text) click to toggle source

    # File lib/termcolor.rb, line 38
    def tag_separate(text)
      re = /<(\/*)([^\W_]+)(?:_(on_[^\W_]+))*(?:_with_([^\W_]+))*(?:_and_([^\W_]+))*>/
      text.gsub(re) do
        matchs = $~.captures
        if matchs.shift.empty?
          tag = ->t{ "<#{t}>" }
        else
          matchs.reverse!
          tag = ->t{ "</#{t}>" }
        end
        matchs.compact.map { |word| tag[word] }.join
      end
    end

test(*args) click to toggle source

    # File lib/termcolor.rb, line 52
    def test(*args)
      args = (0..109).to_a if args.empty?
      args.each_with_index do |color, index|
        print parse("<#{color}> #{color} </#{color}>") + "\t"
        puts if (index + 1) % 10 == 0
      end
    end

unescape(text) click to toggle source

    # File lib/termcolor.rb, line 23
    def unescape(text)
      escape_or_unescape(:unescape, text)
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.