Class: Vedeu::Buffers::Buffer
- Inherits:
-
Object
- Object
- Vedeu::Buffers::Buffer
- Includes:
- 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 ⇒ String|Symbol readonly
-
#previous ⇒ Vedeu::Views::View
The previous buffer which was displayed; contains the content that was shown before ‘front’.
- #repository ⇒ Vedeu::Repositories::Repository included from Repositories::Model
Instance Method Summary collapse
-
#absent?(variable) ⇒ Boolean
included
from Common
private
Returns a boolean indicating whether a variable is nil or empty.
-
#add(content) ⇒ Boolean
Add the content to the back buffer, then update the repository.
-
#back? ⇒ Boolean
Return a boolean indicating content presence on the buffer type.
-
#cursor_visible? ⇒ Boolean
Return a boolean indicating whether the cursor should be visible for this view.
-
#defaults ⇒ Hash<Symbol => NilClass, String>
private
Returns the default options/attributes for this class.
-
#demodulize(klass) ⇒ String
included
from Common
private
Removes the module part from the expression in the string.
-
#front? ⇒ Boolean
Return a boolean indicating content presence on the buffer type.
-
#initialize(attributes = {}) ⇒ Vedeu::Buffers::Buffer
constructor
Return a new instance of Buffer.
-
#present?(variable) ⇒ Boolean
included
from Common
private
Returns a boolean indicating whether a variable has a useful value.
-
#previous? ⇒ Boolean
Return a boolean indicating content presence on the buffer type.
-
#render ⇒ Array<Array<Array<Vedeu::Views::Char>>>
Retrieve the latest content from the buffer.
-
#size ⇒ Fixnum
Returns the number of lines of content for the buffer or 0 if the buffer is empty.
-
#snake_case(name) ⇒ String
included
from Common
private
Converts a class name to a lowercase snake case string.
-
#store ⇒ void
included
from Repositories::Model
The model instance stored in the repository.
-
#swap ⇒ Boolean
private
Return a boolean indicating content was swapped between buffers.
Constructor Details
#initialize(attributes = {}) ⇒ Vedeu::Buffers::Buffer
Return a new instance of Buffer. Generally a Buffer is initialized with only a ‘name’ and ‘back’ parameter.
47 48 49 50 51 |
# File 'lib/vedeu/buffers/buffer.rb', line 47 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.
17 18 19 |
# File 'lib/vedeu/buffers/buffer.rb', line 17 def back @back end |
#front ⇒ Vedeu::Views::View
The currently displayed buffer, contains the content which was last output.
24 25 26 |
# File 'lib/vedeu/buffers/buffer.rb', line 24 def front @front end |
#name ⇒ String|Symbol (readonly)
35 36 37 |
# File 'lib/vedeu/buffers/buffer.rb', line 35 def name @name end |
#previous ⇒ Vedeu::Views::View
The previous buffer which was displayed; contains the content that was shown before ‘front’.
31 32 33 |
# File 'lib/vedeu/buffers/buffer.rb', line 31 def previous @previous end |
#repository ⇒ Vedeu::Repositories::Repository Originally defined in module Repositories::Model
Instance Method Details
#absent?(variable) ⇒ Boolean Originally defined in module Common
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 a boolean indicating whether a variable is nil or empty.
#add(content) ⇒ Boolean
Add the content to the back buffer, then update the repository. Returns boolean indicating that the repository was updated.
59 60 61 62 63 64 65 |
# File 'lib/vedeu/buffers/buffer.rb', line 59 def add(content) @back = content store true end |
#back? ⇒ Boolean
Return a boolean indicating content presence on the buffer type.
71 72 73 74 75 |
# File 'lib/vedeu/buffers/buffer.rb', line 71 def back? return false if back.nil? || back.lines.empty? true end |
#cursor_visible? ⇒ Boolean
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.
92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/vedeu/buffers/buffer.rb', line 92 def cursor_visible? if front? front.cursor_visible? elsif previous? previous.cursor_visible? else Vedeu.interfaces.by_name(name).cursor_visible? end end |
#defaults ⇒ Hash<Symbol => NilClass, String> (private)
Returns the default options/attributes for this class.
179 180 181 182 183 184 185 186 187 |
# File 'lib/vedeu/buffers/buffer.rb', line 179 def defaults { back: nil, front: nil, name: '', previous: nil, repository: Vedeu.buffers, } end |
#demodulize(klass) ⇒ String Originally defined in module Common
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.
Removes the module part from the expression in the string.
#front? ⇒ Boolean
Return a boolean indicating content presence on the buffer type.
109 110 111 112 113 |
# File 'lib/vedeu/buffers/buffer.rb', line 109 def front? return false if front.nil? || front.lines.empty? true end |
#present?(variable) ⇒ Boolean Originally defined in module Common
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 a boolean indicating whether a variable has a useful value.
#previous? ⇒ Boolean
Return a boolean indicating content presence on the buffer type.
119 120 121 122 123 |
# File 'lib/vedeu/buffers/buffer.rb', line 119 def previous? return false if previous.nil? || previous.lines.empty? true end |
#render ⇒ Array<Array<Array<Vedeu::Views::Char>>>
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.
139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
# File 'lib/vedeu/buffers/buffer.rb', line 139 def render if back? swap Vedeu::Output::Viewport.render(front) elsif front? Vedeu::Output::Viewport.render(front) elsif previous? Vedeu::Output::Viewport.render(previous) end end |
#size ⇒ Fixnum
Returns the number of lines of content for the buffer or 0 if the buffer is empty.
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 |
# File 'lib/vedeu/buffers/buffer.rb', line 158 def size if back? back.lines.size elsif front? front.lines.size elsif previous? previous.lines.size else 0 end end |
#snake_case(name) ⇒ String Originally defined in module Common
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.
Converts a class name to a lowercase snake case string.
#store ⇒ void Originally defined in module Repositories::Model
Perhaps some validation could be added here?
If a block is given, store the model, return the model after yielding.
This method returns an undefined value.
Returns The model instance stored in the repository.
#swap ⇒ Boolean (private)
Return a boolean indicating content was swapped between buffers.
193 194 195 196 197 198 199 200 201 202 203 |
# File 'lib/vedeu/buffers/buffer.rb', line 193 def swap Vedeu.log(type: :output, message: "Buffer swapping: '#{name}'".freeze) @previous = front @front = back @back = nil store true end |