Class: Vedeu::Buffer
- Inherits:
-
Object
- Object
- Vedeu::Buffer
- Includes:
- Model
- Defined in:
- lib/vedeu/buffers/buffer.rb
Overview
The Buffer object represents the states of display for an interface. The states are ‘front’, ‘back’ and ‘previous’.
- Back
-
-> [Front] -> [Previous]
The content on the screen, or last output will always be the ‘Front’ buffer. Content due to be displayed on next refresh will come from the ‘Back’ buffer if available, otherwise from the current ‘Front’ buffer. When new content is copied to the ‘Front’ buffer, the current ‘Front’ buffer is also copied to the ‘Previous’ buffer.
Instance Attribute Summary collapse
-
#back ⇒ Interface
The next buffer to be displayed; contains the content which will be shown on next refresh.
-
#front ⇒ Interface
The currently displayed buffer, contains the content which was last output.
- #name ⇒ String readonly
-
#previous ⇒ Interface
The previous buffer which was displayed; contains the content that was shown before ‘front’.
Attributes included from Model
Instance Method Summary collapse
-
#add(content) ⇒ Boolean
Add the content to the back buffer, then update the repository.
-
#buffer ⇒ Array<Array<Array<Vedeu::Char>>>
private
Retrieve the latest content from the buffer.
-
#clear ⇒ void
Returns the front buffer or, if that is empty, the interface cleared.
-
#clear_buffer ⇒ void
private
Clear the buffer.
-
#content_for?(buffer) ⇒ Boolean
private
Return a boolean indicating content presence on the buffer type.
- #defaults ⇒ Hash<Symbol => NilClass, String> private
-
#hide ⇒ void
Hide this buffer.
-
#initialize(attributes = {}) ⇒ Vedeu::Buffer
constructor
Return a new instance of Buffer.
-
#interface ⇒ Vedeu::Interface
private
Retrieve the interface by name.
-
#render ⇒ Array<Array<Array<Vedeu::Char>>>
(also: #content)
Return the content for this buffer.
-
#show ⇒ void
Show this buffer.
-
#swap ⇒ Boolean
private
Return a boolean indicating content was swapped between buffers.
- #view ⇒ Vedeu::Interface private
- #visible? ⇒ Boolean private
Methods included from Model
#demodulize, #deputy, #dsl_class, included, #store
Constructor Details
#initialize(attributes = {}) ⇒ Vedeu::Buffer
Return a new instance of Buffer. Generally a Buffer is initialized with only a ‘name’ and ‘back’ parameter.
52 53 54 55 56 |
# File 'lib/vedeu/buffers/buffer.rb', line 52 def initialize(attributes = {}) @attributes = defaults.merge!(attributes) @attributes.each { |key, value| instance_variable_set("@#{key}", value) } end |
Instance Attribute Details
#back ⇒ Interface
The next buffer to be displayed; contains the content which will be shown on next refresh.
22 23 24 |
# File 'lib/vedeu/buffers/buffer.rb', line 22 def back @back end |
#front ⇒ Interface
The currently displayed buffer, contains the content which was last output.
29 30 31 |
# File 'lib/vedeu/buffers/buffer.rb', line 29 def front @front end |
#name ⇒ String (readonly)
40 41 42 |
# File 'lib/vedeu/buffers/buffer.rb', line 40 def name @name end |
#previous ⇒ Interface
The previous buffer which was displayed; contains the content that was shown before ‘front’.
36 37 38 |
# File 'lib/vedeu/buffers/buffer.rb', line 36 def previous @previous end |
Instance Method Details
#add(content) ⇒ Boolean
Add the content to the back buffer, then update the repository. Returns boolean indicating that the repository was updated.
63 64 65 66 67 68 69 |
# File 'lib/vedeu/buffers/buffer.rb', line 63 def add(content) @back = content store true end |
#buffer ⇒ Array<Array<Array<Vedeu::Char>>> (private)
Retrieve the latest content from the buffer.
120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/vedeu/buffers/buffer.rb', line 120 def buffer swap if content_for?(:back) if content_for?(:front) [front.render] elsif content_for?(:previous) [previous.render] else [] end end |
#clear ⇒ void
This method returns an undefined value.
Returns the front buffer or, if that is empty, the interface cleared.
74 75 76 |
# File 'lib/vedeu/buffers/buffer.rb', line 74 def clear Vedeu::Output.render(clear_buffer) end |
#clear_buffer ⇒ void (private)
This method returns an undefined value.
Clear the buffer.
138 139 140 |
# File 'lib/vedeu/buffers/buffer.rb', line 138 def clear_buffer @clear_buffer ||= Vedeu::Clear.new(view).clear end |
#content_for?(buffer) ⇒ Boolean (private)
Return a boolean indicating content presence on the buffer type.
172 173 174 175 176 177 |
# File 'lib/vedeu/buffers/buffer.rb', line 172 def content_for?(buffer) return false if public_send(buffer).nil? || public_send(buffer).content.empty? true end |
#defaults ⇒ Hash<Symbol => NilClass, String> (private)
143 144 145 146 147 148 149 150 151 |
# File 'lib/vedeu/buffers/buffer.rb', line 143 def defaults { back: nil, front: nil, name: '', previous: nil, repository: Vedeu.buffers, } end |
#hide ⇒ void
This method returns an undefined value.
Hide this buffer.
81 82 83 84 85 86 |
# File 'lib/vedeu/buffers/buffer.rb', line 81 def hide return nil unless visible? Vedeu::Visibility.hide(interface) clear end |
#interface ⇒ Vedeu::Interface (private)
Retrieve the interface by name.
182 183 184 |
# File 'lib/vedeu/buffers/buffer.rb', line 182 def interface @interface ||= Vedeu.interfaces.by_name(name) end |
#render ⇒ Array<Array<Array<Vedeu::Char>>> Also known as: content
Return the content for this buffer.
-
If we have new content (i.e. content on ‘back’) to be shown, we first clear the area occupied by the previous content, then clear the area for the new content, and then finally render the new content.
-
If there is no new content (i.e. ‘back’ is empty), check the ‘front’ buffer and display that.
-
If there is no new content, and the front buffer is empty, display the ‘previous’ buffer.
-
If the ‘previous’ buffer is empty, return an empty collection.
100 101 102 |
# File 'lib/vedeu/buffers/buffer.rb', line 100 def render Vedeu::Output.render(buffer) end |
#show ⇒ void
This method returns an undefined value.
Show this buffer.
108 109 110 111 112 113 |
# File 'lib/vedeu/buffers/buffer.rb', line 108 def show return nil if visible? Vedeu::Visibility.show(interface) render end |
#swap ⇒ Boolean (private)
Return a boolean indicating content was swapped between buffers.
156 157 158 159 160 161 162 163 164 165 166 |
# File 'lib/vedeu/buffers/buffer.rb', line 156 def swap Vedeu.log(type: :output, message: "Buffer swapping: '#{name}'") @previous = front @front = back @back = nil store true end |
#view ⇒ Vedeu::Interface (private)
187 188 189 190 191 192 193 194 195 |
# File 'lib/vedeu/buffers/buffer.rb', line 187 def view if content_for?(:front) front else interface end end |
#visible? ⇒ Boolean (private)
198 199 200 |
# File 'lib/vedeu/buffers/buffer.rb', line 198 def visible? interface.visible? end |