Class: Vedeu::VirtualTerminal
- Inherits:
-
Object
- Object
- Vedeu::VirtualTerminal
- Defined in:
- lib/vedeu/output/virtual_terminal.rb
Overview
Represents a Terminal view.
Instance Attribute Summary collapse
-
#cell_height ⇒ Object
readonly
Returns the value of attribute cell_height.
-
#cell_width ⇒ Object
readonly
Returns the value of attribute cell_width.
-
#height ⇒ Object
readonly
Returns the value of attribute height.
-
#renderer ⇒ Object
Returns the value of attribute renderer.
-
#width ⇒ Object
readonly
Returns the value of attribute width.
Instance Method Summary collapse
- #cells ⇒ Array<Array<Vedeu::Char>>
- #fetch(from, which) ⇒ Array<Vedeu::Char>|Array private
- #initialize(height, width, renderer = HTMLRenderer) ⇒ Vedeu::VirtualTerminal constructor
- #new_virtual_terminal ⇒ Array<Array<Vedeu::Char>> private
-
#output(data) ⇒ Array<Array<Vedeu::Char>>
Write a collection of cells to the virtual terminal.
-
#read(y, x) ⇒ Vedeu::Char
Read a single cell from the virtual terminal.
- #render ⇒ void
-
#reset ⇒ Array<Array<Vedeu::Char>>
(also: #clear)
Removes all content from the virtual terminal; effectively clearing it.
-
#write(y, x, data) ⇒ Vedeu::Char
Write a single cell to the virtual terminal.
Constructor Details
#initialize(height, width, renderer = HTMLRenderer) ⇒ Vedeu::VirtualTerminal
14 15 16 17 18 19 |
# File 'lib/vedeu/output/virtual_terminal.rb', line 14 def initialize(height, width, renderer = HTMLRenderer) @cell_height, @cell_width = Vedeu::PositionIndex[height, width] @height = height @width = width @renderer = renderer end |
Instance Attribute Details
#cell_height ⇒ Object (readonly)
Returns the value of attribute cell_height.
8 9 10 |
# File 'lib/vedeu/output/virtual_terminal.rb', line 8 def cell_height @cell_height end |
#cell_width ⇒ Object (readonly)
Returns the value of attribute cell_width.
8 9 10 |
# File 'lib/vedeu/output/virtual_terminal.rb', line 8 def cell_width @cell_width end |
#height ⇒ Object (readonly)
Returns the value of attribute height.
8 9 10 |
# File 'lib/vedeu/output/virtual_terminal.rb', line 8 def height @height end |
#renderer ⇒ Object
Returns the value of attribute renderer.
7 8 9 |
# File 'lib/vedeu/output/virtual_terminal.rb', line 7 def renderer @renderer end |
#width ⇒ Object (readonly)
Returns the value of attribute width.
8 9 10 |
# File 'lib/vedeu/output/virtual_terminal.rb', line 8 def width @width end |
Instance Method Details
#cells ⇒ Array<Array<Vedeu::Char>>
22 23 24 |
# File 'lib/vedeu/output/virtual_terminal.rb', line 22 def cells @cells ||= new_virtual_terminal end |
#fetch(from, which) ⇒ Array<Vedeu::Char>|Array (private)
86 87 88 |
# File 'lib/vedeu/output/virtual_terminal.rb', line 86 def fetch(from, which) from[which] || [] end |
#new_virtual_terminal ⇒ Array<Array<Vedeu::Char>> (private)
91 92 93 |
# File 'lib/vedeu/output/virtual_terminal.rb', line 91 def new_virtual_terminal Array.new(cell_height) { Array.new(cell_width) { Vedeu::Char.new } } end |
#output(data) ⇒ Array<Array<Vedeu::Char>>
Write a collection of cells to the virtual terminal.
44 45 46 47 48 49 50 |
# File 'lib/vedeu/output/virtual_terminal.rb', line 44 def output(data) Array(data).flatten.each do |char| write(char.y, char.x, char) if char.is_a?(Vedeu::Char) end cells end |
#read(y, x) ⇒ Vedeu::Char
Read a single cell from the virtual terminal.
31 32 33 34 35 36 37 38 |
# File 'lib/vedeu/output/virtual_terminal.rb', line 31 def read(y, x) cy, cx = Vedeu::PositionIndex[y, x] row = fetch(cells, cy) cell = fetch(row, cx) cell end |
#render ⇒ void
This method returns an undefined value.
53 54 55 |
# File 'lib/vedeu/output/virtual_terminal.rb', line 53 def render renderer.render(cells) end |
#reset ⇒ Array<Array<Vedeu::Char>> Also known as: clear
Removes all content from the virtual terminal; effectively clearing it.
60 61 62 |
# File 'lib/vedeu/output/virtual_terminal.rb', line 60 def reset @cells = new_virtual_terminal end |
#write(y, x, data) ⇒ Vedeu::Char
Write a single cell to the virtual terminal.
71 72 73 74 75 76 77 78 79 |
# File 'lib/vedeu/output/virtual_terminal.rb', line 71 def write(y, x, data) cy, cx = Vedeu::PositionIndex[y, x] return false unless read(cy, cx).is_a?(Vedeu::Char) cells[cy][cx] = data true end |