class AnsiSys::Characters

Constants

WIDTHS

widths of characters

Attributes

sgr[R]
string[R]

Public Class Methods

new(string, sgr) click to toggle source
# File lib/ansisys.rb, line 112
def initialize(string, sgr)
        @string = string
        @sgr = sgr
end

Public Instance Methods

echo_on(screen, cursor, kcode = nil) click to toggle source

echo the string onto the screen with initial cursor as cursor cursor position will be changed as the string is echoed

# File lib/ansisys.rb, line 119
def echo_on(screen, cursor, kcode = nil)
        each_char(kcode) do |c|
                w = width(c)
                cursor.fit!(w)
                screen.write(c, w, cursor.cur_col, cursor.cur_row, @sgr.dup)
                cursor.advance!(w)
        end
        return self
end

Private Instance Methods

each_char(kcode) { |c| ... } click to toggle source

iterator on each character

# File lib/ansisys.rb, line 131
def each_char(kcode, &block)
        @string.scan(Regexp.new('.', nil, kcode)).each do |c|
                yield(c)
        end
end
width(char) click to toggle source

width of a character

# File lib/ansisys.rb, line 138
def width(char)
        if WIDTHS.has_key?(char)
                return WIDTHS[char]
        end
        case char.size       # expecting number of bytes
        when 1
                return 1
        else
                return 2
        end
end