Class: Vedeu::Output
- Inherits:
-
Object
- Object
- Vedeu::Output
- Defined in:
- lib/vedeu/output/output.rb
Overview
Sends the interface to the terminal or output device.
Instance Attribute Summary collapse
-
#interface ⇒ Object
readonly
private
Returns the value of attribute interface.
Class Method Summary collapse
-
.clear(interface) ⇒ Array|String
Clears the area defined by the interface.
-
.render(interface) ⇒ Array|String
Writes content (the provided interface object with associated lines, streams, colours and styles) to the area defined by the interface.
Instance Method Summary collapse
- #char_builder(value, iy, ix) ⇒ Vedeu::Char private
-
#clear ⇒ Array
Clear the view and send to the terminal.
-
#initialize(interface) ⇒ Output
constructor
Return a new instance of Output.
-
#origin(y_index = 0, x_index = 0) ⇒ Vedeu::Position
private
Returns the position of the cursor at the top-left coordinate, relative to the interface’s position.
-
#render ⇒ Array
Send the view to the terminal.
- #viewport ⇒ void private
-
#virtual_clear ⇒ Array<Array<Vedeu::Char>>
private
For each visible line of the interface, set the foreground and background colours to those specified when the interface was defined, then starting write space characters over the area which the interface occupies.
-
#virtual_view ⇒ Array<Array<Vedeu::Char>>
private
Builds up a virtual view; a grid of Vedeu::Char objects- each one holding one character along with its colour, style and position attributes.
-
#virtual_x ⇒ Array
private
Provides a virtual x position within the interface’s dimensions.
-
#virtual_y ⇒ Array
private
Provides a virtual y position within the interface’s dimensions.
Constructor Details
#initialize(interface) ⇒ Output
Return a new instance of Output.
28 29 30 |
# File 'lib/vedeu/output/output.rb', line 28 def initialize(interface) @interface = interface end |
Instance Attribute Details
#interface ⇒ Object (readonly, private)
Returns the value of attribute interface.
60 61 62 |
# File 'lib/vedeu/output/output.rb', line 60 def interface @interface end |
Class Method Details
.clear(interface) ⇒ Array|String
Clears the area defined by the interface.
11 12 13 |
# File 'lib/vedeu/output/output.rb', line 11 def self.clear(interface) new(interface).clear end |
.render(interface) ⇒ Array|String
Writes content (the provided interface object with associated lines, streams, colours and styles) to the area defined by the interface.
20 21 22 |
# File 'lib/vedeu/output/output.rb', line 20 def self.render(interface) new(interface).render end |
Instance Method Details
#char_builder(value, iy, ix) ⇒ Vedeu::Char (private)
122 123 124 125 126 127 |
# File 'lib/vedeu/output/output.rb', line 122 def char_builder(value, iy, ix) Vedeu::Char.new({ value: value, colour: interface.colour, style: interface.style, position: origin(iy, ix) }) end |
#clear ⇒ Array
Clear the view and send to the terminal.
35 36 37 38 39 40 41 42 43 |
# File 'lib/vedeu/output/output.rb', line 35 def clear if Vedeu::Configuration.drb? Vedeu.trigger(:_drb_store_output_, virtual_clear) HTMLRenderer.to_file(VirtualBuffer.retrieve) end Terminal.output(Renderer.render(virtual_clear)) end |
#origin(y_index = 0, x_index = 0) ⇒ Vedeu::Position (private)
Returns the position of the cursor at the top-left coordinate, relative to the interface’s position.
135 136 137 |
# File 'lib/vedeu/output/output.rb', line 135 def origin(y_index = 0, x_index = 0) Vedeu::Position.new(virtual_y[y_index], virtual_x[x_index]) end |
#render ⇒ Array
Send the view to the terminal.
48 49 50 51 52 53 54 55 56 |
# File 'lib/vedeu/output/output.rb', line 48 def render if Vedeu::Configuration.drb? Vedeu.trigger(:_drb_store_output_, virtual_view) HTMLRenderer.to_file(VirtualBuffer.retrieve) end Terminal.output(Renderer.render(virtual_view, interface.cursor)) end |
#viewport ⇒ void (private)
This method returns an undefined value.
114 115 116 |
# File 'lib/vedeu/output/output.rb', line 114 def @viewport ||= Vedeu::Viewport.new(interface).render end |
#virtual_clear ⇒ Array<Array<Vedeu::Char>> (private)
omg!
For each visible line of the interface, set the foreground and background colours to those specified when the interface was defined, then starting write space characters over the area which the interface occupies.
70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/vedeu/output/output.rb', line 70 def virtual_clear Vedeu.log(type: :output, message: "Clearing: '#{interface.name}'") out = [] interface.height.times do |iy| row = [] interface.width.times do |ix| row << char_builder(' ', iy, ix) end out << row end out end |
#virtual_view ⇒ Array<Array<Vedeu::Char>> (private)
omg!
Builds up a virtual view; a grid of Vedeu::Char objects- each one holding one character along with its colour, style and position attributes.
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/vedeu/output/output.rb', line 91 def virtual_view out = [ virtual_clear ] Vedeu.log(type: :output, message: "Rendering: '#{interface.name}'") .each_with_index do |line, iy| row = [] line.each_with_index do |char, ix| row << if char.is_a?(Vedeu::Char) && (char.x != ix || char.y != iy) char.position = origin(iy, ix) char else char_builder(char, iy, ix) end end out << row end out end |
#virtual_x ⇒ Array (private)
Provides a virtual x position within the interface’s dimensions.
159 160 161 |
# File 'lib/vedeu/output/output.rb', line 159 def virtual_x @virtual_x ||= (interface.left...interface.right).to_a end |
#virtual_y ⇒ Array (private)
Provides a virtual y position within the interface’s dimensions.
147 148 149 |
# File 'lib/vedeu/output/output.rb', line 147 def virtual_y @virtual_y ||= (interface.top...interface.bottom).to_a end |