Class: TTYString::Screen
- Inherits:
-
Object
- Object
- TTYString::Screen
- Defined in:
- lib/tty_string/screen.rb
Overview
a grid to draw on
Instance Attribute Summary collapse
-
#cursor ⇒ Object
readonly
Returns the value of attribute cursor.
Instance Method Summary collapse
- #[](row, col) ⇒ Object
- #[]=(row, col, *value) ⇒ Object
- #clear ⇒ Object
- #clear_at_cursor ⇒ Object
- #clear_backward ⇒ Object
- #clear_forward ⇒ Object
- #clear_line ⇒ Object
- #clear_line_backward ⇒ Object
- #clear_line_forward ⇒ Object
- #clear_lines_after ⇒ Object
- #clear_lines_before ⇒ Object
-
#initialize ⇒ Screen
constructor
A new instance of Screen.
- #to_s ⇒ Object
- #write(string) ⇒ Object
Constructor Details
Instance Attribute Details
#cursor ⇒ Object (readonly)
Returns the value of attribute cursor.
8 9 10 |
# File 'lib/tty_string/screen.rb', line 8 def cursor @cursor end |
Instance Method Details
#[](row, col) ⇒ Object
24 25 26 27 |
# File 'lib/tty_string/screen.rb', line 24 def []((row, col)) screen[row] ||= [] screen[row][col] end |
#[]=(row, col, *value) ⇒ Object
19 20 21 22 |
# File 'lib/tty_string/screen.rb', line 19 def []=((row, col), *value) screen[row] ||= [] screen[row][col] = value.flatten(1) end |
#clear ⇒ Object
45 46 47 |
# File 'lib/tty_string/screen.rb', line 45 def clear @screen = [] end |
#clear_at_cursor ⇒ Object
29 30 31 |
# File 'lib/tty_string/screen.rb', line 29 def clear_at_cursor self[cursor] = nil end |
#clear_backward ⇒ Object
57 58 59 60 |
# File 'lib/tty_string/screen.rb', line 57 def clear_backward clear_line_backward clear_lines_before end |
#clear_forward ⇒ Object
62 63 64 65 |
# File 'lib/tty_string/screen.rb', line 62 def clear_forward clear_lines_after clear_line_forward end |
#clear_line ⇒ Object
41 42 43 |
# File 'lib/tty_string/screen.rb', line 41 def clear_line screen[row] = [] end |
#clear_line_backward ⇒ Object
37 38 39 |
# File 'lib/tty_string/screen.rb', line 37 def clear_line_backward screen[row].fill(nil, 0..col) end |
#clear_line_forward ⇒ Object
33 34 35 |
# File 'lib/tty_string/screen.rb', line 33 def clear_line_forward screen[row].fill(nil, col..-1) end |
#clear_lines_after ⇒ Object
53 54 55 |
# File 'lib/tty_string/screen.rb', line 53 def clear_lines_after screen.slice!((row + 1)..-1) end |
#clear_lines_before ⇒ Object
49 50 51 |
# File 'lib/tty_string/screen.rb', line 49 def clear_lines_before screen.fill([], 0...row) end |
#to_s ⇒ Object
15 16 17 |
# 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) ⇒ Object
67 68 69 70 71 72 73 74 |
# File 'lib/tty_string/screen.rb', line 67 def write(string) return self[cursor] if string.empty? string.each_char do |char| self[cursor] = char cursor.right end end |