Class: AnsiSys::Characters

Inherits:
Object
  • Object
show all
Defined in:
lib/ansisys.rb

Constant Summary collapse

WIDTHS =

widths of characters

{
  "\t" => 8,
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(string, sgr) ⇒ Characters

Returns a new instance of Characters.



94
95
96
97
# File 'lib/ansisys.rb', line 94

def initialize(string, sgr)
  @string = string
  @sgr = sgr
end

Instance Attribute Details

#sgrObject (readonly)

Select Graphic Rendition associated with the text



92
93
94
# File 'lib/ansisys.rb', line 92

def sgr
  @sgr
end

#stringObject (readonly)

clear text



91
92
93
# File 'lib/ansisys.rb', line 91

def string
  @string
end

Instance Method Details

#echo_on(screen, cursor, kcode = nil) ⇒ Object

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



101
102
103
104
105
106
107
108
109
# File 'lib/ansisys.rb', line 101

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