class TTYString::Screen
a grid to draw on
Attributes
cursor[R]
screen[R]
Public Class Methods
new()
click to toggle source
# File lib/tty_string/screen.rb, line 10 def initialize @cursor = Cursor.new @screen = [] end
Public Instance Methods
[]((row, col))
click to toggle source
# File lib/tty_string/screen.rb, line 24 def []((row, col)) screen[row] ||= [] screen[row][col] end
[]=((row, col), *value)
click to toggle source
# File lib/tty_string/screen.rb, line 19 def []=((row, col), *value) screen[row] ||= [] screen[row][col] = value.flatten(1) end
clear()
click to toggle source
# File lib/tty_string/screen.rb, line 45 def clear @screen = [] end
clear_at_cursor()
click to toggle source
# File lib/tty_string/screen.rb, line 29 def clear_at_cursor self[cursor] = nil end
clear_backward()
click to toggle source
# File lib/tty_string/screen.rb, line 67 def clear_backward clear_line_backward clear_lines_before end
clear_forward()
click to toggle source
# File lib/tty_string/screen.rb, line 72 def clear_forward clear_lines_after clear_line_forward end
clear_line()
click to toggle source
# File lib/tty_string/screen.rb, line 41 def clear_line screen[row] = [] end
clear_line_backward()
click to toggle source
# File lib/tty_string/screen.rb, line 37 def clear_line_backward screen[row].fill(nil, 0..col) end
clear_line_forward()
click to toggle source
# File lib/tty_string/screen.rb, line 33 def clear_line_forward screen[row].fill(nil, col..-1) end
clear_lines_after()
click to toggle source
# File lib/tty_string/screen.rb, line 63 def clear_lines_after screen.slice!((row + 1)..-1) end
clear_lines_before()
click to toggle source
# File lib/tty_string/screen.rb, line 59 def clear_lines_before screen.fill([], 0...row) end
scroll_down()
click to toggle source
# File lib/tty_string/screen.rb, line 54 def scroll_down screen.unshift([]) screen.pop end
scroll_up()
click to toggle source
# File lib/tty_string/screen.rb, line 49 def scroll_up screen.push([]) screen.shift end
to_s()
click to toggle source
# File lib/tty_string/screen.rb, line 15 def to_s screen.map { |c| Array(c).map { |x| x || ' ' }.join.rstrip }.join("\n") end
write(string)
click to toggle source
# File lib/tty_string/screen.rb, line 77 def write(string) return self[cursor] if string.empty? string.each_char do |char| self[cursor] = char cursor.right end end
Private Instance Methods
col()
click to toggle source
# File lib/tty_string/screen.rb, line 94 def col cursor.col end
row()
click to toggle source
# File lib/tty_string/screen.rb, line 90 def row cursor.row end