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(view, refresh = false) ⇒ Boolean
Add the view to the back buffer, then update the repository.
-
#back? ⇒ Boolean
Return a boolean indicating content presence on the buffer type.
-
#become(klass, attributes) ⇒ Class
included
from Common
private
Converts one class into another.
-
#boolean(value) ⇒ Boolean
included
from Common
private
Returns a boolean indicating the value was a boolean.
-
#boolean?(value) ⇒ Boolean
included
from Common
private
Returns a boolean indicating whether the value is a Boolean.
-
#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.
-
#escape?(value) ⇒ Boolean
included
from Common
private
Returns a boolean indicating whether the value is an escape sequence object (e.g. Cells::Escape.).
-
#falsy?(value) ⇒ Boolean
included
from Common
private
Returns a boolean indicating whether the value should be considered false.
-
#front? ⇒ Boolean
Return a boolean indicating content presence on the buffer type.
-
#hash?(value) ⇒ Boolean
included
from Common
private
Returns a boolean indicating whether the value is a Hash.
-
#initialize(attributes = {}) ⇒ Vedeu::Buffers::Buffer
constructor
Return a new instance of Buffer.
- #interface ⇒ Vedeu::Interfaces::Interface private
-
#line_model? ⇒ Boolean
included
from Common
private
Returns a boolean indicating the model is a Views::Line.
-
#numeric?(value) ⇒ Boolean
included
from Common
private
Returns a boolean indicating whether the value is a Fixnum.
-
#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::Cells::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(klass) ⇒ String
included
from Common
private
Converts a class name to a lowercase snake case string.
-
#store(&block) ⇒ void
included
from Repositories::Model
The model instance stored in the repository.
-
#stream_model? ⇒ Boolean
included
from Common
private
Returns a boolean indicating the model is a Views::Stream.
-
#string?(value) ⇒ Boolean
included
from Common
private
Returns a boolean indicating whether the value is a Fixnum.
-
#swap ⇒ Boolean
private
Return a boolean indicating content was swapped between buffers.
-
#truthy?(value) ⇒ Boolean
included
from Common
private
Returns a boolean indicating whether the value should be considered true.
-
#view_model? ⇒ Boolean
included
from Common
private
Returns a boolean indicating the model is a Views::View.
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.
49 50 51 52 53 |
# File 'lib/vedeu/buffers/buffer.rb', line 49 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.
19 20 21 |
# File 'lib/vedeu/buffers/buffer.rb', line 19 def back @back end |
#front ⇒ Vedeu::Views::View
The currently displayed buffer, contains the content which was last output.
26 27 28 |
# File 'lib/vedeu/buffers/buffer.rb', line 26 def front @front end |
#name ⇒ String|Symbol (readonly)
37 38 39 |
# File 'lib/vedeu/buffers/buffer.rb', line 37 def name @name end |
#previous ⇒ Vedeu::Views::View
The previous buffer which was displayed; contains the content that was shown before ‘front’.
33 34 35 |
# File 'lib/vedeu/buffers/buffer.rb', line 33 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(view, refresh = false) ⇒ Boolean
Add the view to the back buffer, then update the repository. Returns boolean indicating that the repository was updated.
62 63 64 65 66 67 68 69 70 |
# File 'lib/vedeu/buffers/buffer.rb', line 62 def add(view, refresh = false) @back = view store Vedeu.trigger(:_refresh_view_, view.name) if boolean(refresh) true end |
#back? ⇒ Boolean
Return a boolean indicating content presence on the buffer type.
76 77 78 |
# File 'lib/vedeu/buffers/buffer.rb', line 76 def back? (back.nil? || back.lines.empty?) ? false : true end |
#become(klass, attributes) ⇒ Class 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 one class into another.
#boolean(value) ⇒ 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 the value was a boolean.
#boolean?(value) ⇒ 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 the value is a Boolean.
#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.
95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/vedeu/buffers/buffer.rb', line 95 def cursor_visible? if front? front.cursor_visible? elsif previous? previous.cursor_visible? else interface.cursor_visible? end end |
#defaults ⇒ Hash<Symbol => NilClass, String> (private)
Returns the default options/attributes for this class.
180 181 182 183 184 185 186 187 188 |
# File 'lib/vedeu/buffers/buffer.rb', line 180 def defaults { back: nil, front: nil, name: '', previous: nil, repository: Vedeu.buffers, } end |
#escape?(value) ⇒ 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 the value is an escape sequence object (e.g. Vedeu::Cells::Escape.)
#falsy?(value) ⇒ 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 the value should be considered false.
#front? ⇒ Boolean
Return a boolean indicating content presence on the buffer type.
112 113 114 |
# File 'lib/vedeu/buffers/buffer.rb', line 112 def front? (front.nil? || front.lines.empty?) ? false : true end |
#hash?(value) ⇒ 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 the value is a Hash.
#interface ⇒ Vedeu::Interfaces::Interface (private)
191 192 193 |
# File 'lib/vedeu/buffers/buffer.rb', line 191 def interface Vedeu.interfaces.by_name(name) end |
#line_model? ⇒ 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 the model is a Views::Line.
#numeric?(value) ⇒ 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 the value is a Fixnum.
#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.
120 121 122 |
# File 'lib/vedeu/buffers/buffer.rb', line 120 def previous? (previous.nil? || previous.lines.empty?) ? false : true end |
#render ⇒ Array<Array<Array<Vedeu::Cells::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.
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/vedeu/buffers/buffer.rb', line 138 def render current = if back? swap front elsif front? front elsif previous? previous end Vedeu::Output::Viewport.render(current) unless current.nil? end |
#size ⇒ Fixnum
Returns the number of lines of content for the buffer or 0 if the buffer is empty.
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
# File 'lib/vedeu/buffers/buffer.rb', line 159 def size if back? back.lines.size elsif front? front.lines.size elsif previous? previous.lines.size else 0 end end |
#snake_case(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.
Converts a class name to a lowercase snake case string.
#store(&block) ⇒ 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.
#stream_model? ⇒ 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 the model is a Views::Stream.
#string?(value) ⇒ 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 the value is a Fixnum.
#swap ⇒ Boolean (private)
Return a boolean indicating content was swapped between buffers.
199 200 201 202 203 204 205 206 207 208 209 |
# File 'lib/vedeu/buffers/buffer.rb', line 199 def swap Vedeu.log(type: :buffer, message: "Buffer swapping: '#{name}'") @previous = front @front = back @back = nil store true end |
#truthy?(value) ⇒ 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 the value should be considered true.
#view_model? ⇒ 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 the model is a Views::View.