class WindowTerminal::ColoredText

A subclass of Text for colored window text.

Public Class Methods

new(orientation,text,y,color=:green) click to toggle source

Initializes a ColoredText object.

Calls superclass method WindowTerminal::Text::new
# File lib/accu-window.rb, line 215
def initialize(orientation,text,y,color=:green)
        @color = color
        text = colorize(text)
        super(orientation,text,y)
end

Public Instance Methods

set_text(text) click to toggle source

Sets text while taking into account colorization.

Calls superclass method WindowTerminal::Text#set_text
# File lib/accu-window.rb, line 239
def set_text(text)
        super(colorize(text))
end
to_s() click to toggle source

Makes to_s return something more meaningful.

# File lib/accu-window.rb, line 245
def to_s
        "<ColoredText @orientation=#{@orientation.to_s}, @y=#{@y}, @color=#{@color.to_s} >"
end

Private Instance Methods

colorize(text) click to toggle source
# File lib/accu-window.rb, line 221
def colorize(text)
        if WindowTerminal.os == :linux then
                if @color == :green then
                        text = "\e[#{32}m#{text}\e[0m"
                elsif @color == :red then
                        text = "\e[#{31}m#{text}\e[0m"
                elsif @color == :yellow then
                        text = "\e[#{33}m#{text}\e[0m"
                elsif @color == :pink then
                        text = "\e[#{35}m#{text}\e[0m"
                end
        end
        text
end