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.
- #scroll_down ⇒ Object
- #scroll_up ⇒ Object
- #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
67 68 69 70 |
# File 'lib/tty_string/screen.rb', line 67 def clear_backward clear_line_backward clear_lines_before end |
#clear_forward ⇒ Object
72 73 74 75 |
# File 'lib/tty_string/screen.rb', line 72 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
63 64 65 |
# File 'lib/tty_string/screen.rb', line 63 def clear_lines_after screen.slice!((row + 1)..-1) end |
#clear_lines_before ⇒ Object
59 60 61 |
# File 'lib/tty_string/screen.rb', line 59 def clear_lines_before screen.fill([], 0...row) end |
#scroll_down ⇒ Object
54 55 56 57 |
# File 'lib/tty_string/screen.rb', line 54 def scroll_down screen.unshift([]) screen.pop end |
#scroll_up ⇒ Object
49 50 51 52 |
# File 'lib/tty_string/screen.rb', line 49 def scroll_up screen.push([]) screen.shift 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
77 78 79 80 81 82 83 84 |
# 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 |