Class: Vedeu::Buffers::Buffer
- Inherits:
-
Object
- Object
- Vedeu::Buffers::Buffer
- Includes:
- Common, Repositories::Model
- Defined in:
- lib/vedeu/buffers/buffer.rb,
lib/vedeu/buffers/repository.rb
Overview
Repository
Instance Attribute Summary collapse
-
#back ⇒ Vedeu::Views::View
The next buffer to be displayed; contains the content which will be shown on next refresh.
-
#front ⇒ Vedeu::Views::View
The currently displayed buffer, contains the content which was last output.
-
#name ⇒ NilClass|Symbol|String
readonly
private
The name of the model, the target model or the name of the associated model.
-
#previous ⇒ Vedeu::Views::View
The previous buffer which was displayed; contains the content that was shown before ‘front’.
Attributes included from Repositories::Model
Instance Method Summary collapse
-
#add(view, refresh = false) ⇒ Boolean
private
Add the view to the back buffer, then update the repository.
-
#back? ⇒ Boolean
private
Return a boolean indicating content presence on the buffer type.
- #current ⇒ Vedeu::Views::View|NilClass private private
-
#cursor_visible? ⇒ Boolean
private
Return a boolean indicating whether the cursor should be visible for this view.
-
#defaults ⇒ Hash<Symbol => void>
private
private
The default options/attributes for a new instance of this class.
-
#front? ⇒ Boolean
private
Return a boolean indicating content presence on the buffer type.
-
#initialize(attributes = {}) ⇒ Vedeu::Buffers::Buffer
constructor
private
Return a new instance of Buffer.
-
#interface ⇒ Vedeu::Interfaces::Interface
private
private
Returns the named interface/view from the interfaces repository.
-
#previous? ⇒ Boolean
private
Return a boolean indicating content presence on the buffer type.
-
#render ⇒ Array<Array<Array<Vedeu::Cells::Char>>>
private
Retrieve the latest content from the buffer.
-
#size ⇒ Fixnum
private
Returns the number of lines of content for the buffer or 0 if the buffer is empty.
-
#swap ⇒ Boolean
private
private
Return a boolean indicating content was swapped between buffers.
Methods included from Repositories::Model
Methods included from Common
#absent?, #array?, #boolean, #boolean?, #empty_value?, #escape?, #falsy?, #hash?, #line_model?, #numeric?, #positionable?, #present?, #snake_case, #stream_model?, #string?, #symbol?, #truthy?, #view_model?
Constructor Details
#initialize(attributes = {}) ⇒ Vedeu::Buffers::Buffer
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
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 = {}) defaults.merge!(attributes).each do |key, value| instance_variable_set("@#{key}", value) end end |
Instance Attribute Details
#back ⇒ Vedeu::Views::View
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 ⇒ Vedeu::Views::View
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 ⇒ NilClass|Symbol|String (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns The name of the model, the target model or the name of the associated model.
40 41 42 |
# File 'lib/vedeu/buffers/buffer.rb', line 40 def name @name end |
#previous ⇒ Vedeu::Views::View
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(view, refresh = false) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Add the view to the back buffer, then update the repository. Returns boolean indicating that the repository was updated.
65 66 67 68 69 70 71 72 73 |
# File 'lib/vedeu/buffers/buffer.rb', line 65 def add(view, refresh = false) @back = view store Vedeu.trigger(:_refresh_view_, view.name) if boolean(refresh) true end |
#back? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Return a boolean indicating content presence on the buffer type.
79 80 81 |
# File 'lib/vedeu/buffers/buffer.rb', line 79 def back? (back.nil? || back.lines.empty?) ? false : true end |
#current ⇒ Vedeu::Views::View|NilClass (private)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
168 169 170 171 172 173 174 175 176 177 178 179 180 181 |
# File 'lib/vedeu/buffers/buffer.rb', line 168 def current if back? swap front elsif front? front elsif previous? previous end end |
#cursor_visible? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Return a boolean indicating whether the cursor should be visible for this view.
On a per-view (and per-interface) basis, the cursor can be set to be visible or not visible.
-
If the cursor is visible, then refresh actions or events involving the cursor will act as normal; hiding and showing as the view is rendered or as events are triggered to change the visibility state.
-
If the cursor is not visible, then refresh actions and events involving the cursor will be ignored- the cursor is not shown, so do no work.
98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/vedeu/buffers/buffer.rb', line 98 def cursor_visible? if front? front.cursor_visible? elsif previous? previous.cursor_visible? else interface.cursor_visible? end end |
#defaults ⇒ Hash<Symbol => void> (private)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
The default options/attributes for a new instance of this class.
184 185 186 187 188 189 190 191 192 |
# File 'lib/vedeu/buffers/buffer.rb', line 184 def defaults { back: nil, front: nil, name: nil, previous: nil, repository: Vedeu.buffers, } end |
#front? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Return a boolean indicating content presence on the buffer type.
115 116 117 |
# File 'lib/vedeu/buffers/buffer.rb', line 115 def front? (front.nil? || front.lines.empty?) ? false : true end |
#interface ⇒ Vedeu::Interfaces::Interface (private)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns the named interface/view from the interfaces repository.
195 196 197 |
# File 'lib/vedeu/buffers/buffer.rb', line 195 def interface Vedeu.interfaces.by_name(name) end |
#previous? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Return a boolean indicating content presence on the buffer type.
123 124 125 |
# File 'lib/vedeu/buffers/buffer.rb', line 123 def previous? (previous.nil? || previous.lines.empty?) ? false : true end |
#render ⇒ Array<Array<Array<Vedeu::Cells::Char>>>
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Retrieve the latest content from the 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.
141 142 143 |
# File 'lib/vedeu/buffers/buffer.rb', line 141 def render Vedeu::Output::Viewport.render(current) end |
#size ⇒ Fixnum
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns the number of lines of content for the buffer or 0 if the buffer is empty.
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
# File 'lib/vedeu/buffers/buffer.rb', line 149 def size if back? back.lines.size elsif front? front.lines.size elsif previous? previous.lines.size else 0 end end |
#swap ⇒ Boolean (private)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Return a boolean indicating content was swapped between buffers.
203 204 205 206 207 208 209 210 211 212 213 |
# File 'lib/vedeu/buffers/buffer.rb', line 203 def swap Vedeu.log(type: :buffer, message: "Buffer swapping: '#{name}'") @previous = front @front = back @back = nil store true end |