Class: Vedeu::Cursors::Cursor
- Inherits:
-
Object
- Object
- Vedeu::Cursors::Cursor
- Extended by:
- Forwardable
- Includes:
- Repositories::Model, Toggleable
- Defined in:
- lib/vedeu/cursors/cursor.rb,
lib/vedeu/cursors/repository.rb
Overview
Repository
Instance Attribute Summary collapse
- #name ⇒ String|Symbol readonly private
- #ox ⇒ Fixnum private
- #oy ⇒ Fixnum private
- #repository ⇒ Vedeu::Repositories::Repository included from Repositories::Model
-
#visible ⇒ Boolean
(also: #visible?)
included
from Toggleable
Whether the toggleable is visible.
-
#x ⇒ Fixnum
private
The column/character coordinate.
-
#y ⇒ Fixnum
private
The row/line coordinate.
Class Method Summary collapse
Instance Method Summary collapse
-
#absent?(variable) ⇒ Boolean
included
from Vedeu::Common
private
Returns a boolean indicating whether a variable is nil or empty.
- #attributes ⇒ Hash<Symbol => Boolean|Fixnum|String| Vedeu::Cursors::Repository> private
-
#coordinate(offset, type) ⇒ Vedeu::Geometry::Coordinate
private
private
Determine correct x and y related coordinates.
-
#defaults ⇒ Hash<Symbol => Boolean|Fixnum|String| Vedeu::Cursors::Repository>
private
private
The default values for a new instance of this class.
-
#demodulize(klass) ⇒ String
included
from Vedeu::Common
private
Removes the module part from the expression in the string.
-
#eql?(other) ⇒ Boolean
(also: #==)
private
An object is equal when its values are the same.
- #escape_sequence ⇒ Vedeu::Models::Escape private private
-
#geometry ⇒ Object
private
private
Returns the geometry for the interface.
-
#hide ⇒ Vedeu::Models::Escape
private
Hide a named cursor, or without a name, the cursor of the currently focussed interface.
-
#initialize(attributes = {}) ⇒ Vedeu::Cursors::Cursor
constructor
private
Returns a new instance of Vedeu::Cursors::Cursor.
-
#move_down ⇒ Vedeu::Cursors::Cursor
private
Moves the cursor down by one row.
-
#move_left ⇒ Vedeu::Cursors::Cursor
private
Moves the cursor left by one column.
-
#move_origin ⇒ Vedeu::Cursors::Cursor
private
Moves the cursor to the top left of the named interface.
-
#move_right ⇒ Vedeu::Cursors::Cursor
private
Moves the cursor right by one column.
-
#move_up ⇒ Vedeu::Cursors::Cursor
private
Moves the cursor up by one row.
- #new_attributes(new_y = y, new_x = x, new_oy = oy, new_ox = ox) ⇒ Hash<Symbol => Fixnum> private private
-
#position ⇒ Vedeu::Geometry::Position
private
Return the position of this cursor.
-
#present?(variable) ⇒ Boolean
included
from Vedeu::Common
private
Returns a boolean indicating whether a variable has a useful value.
-
#render ⇒ Array<Vedeu::Models::Escape>
private
Renders the cursor.
-
#show ⇒ Vedeu::Models::Escape
private
Show a named cursor, or without a name, the cursor of the currently focussed interface.
-
#snake_case(name) ⇒ String
included
from Vedeu::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.
-
#store_and_refresh ⇒ void
private
private
Store the cursor and refresh the cursor.
- #to_a ⇒ Array<Fixnum> private
-
#to_s ⇒ String
(also: #to_str)
private
Returns an escape sequence to position the cursor and set its visibility.
-
#toggle ⇒ FalseClass|TrueClass
included
from Toggleable
Toggle the visible state and store the model.
-
#visibility ⇒ String
private
private
Returns the escape sequence for setting the visibility of the cursor.
Constructor Details
#initialize(attributes = {}) ⇒ Vedeu::Cursors::Cursor
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 new instance of Vedeu::Cursors::Cursor.
65 66 67 68 69 |
# File 'lib/vedeu/cursors/cursor.rb', line 65 def initialize(attributes = {}) defaults.merge!(attributes).each do |key, value| instance_variable_set("@#{key}", value) end end |
Instance Attribute Details
#name ⇒ String|Symbol (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.
24 25 26 |
# File 'lib/vedeu/cursors/cursor.rb', line 24 def name @name end |
#ox ⇒ 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.
206 207 208 |
# File 'lib/vedeu/cursors/cursor.rb', line 206 def ox @ox = @ox < 0 ? 0 : @ox end |
#oy ⇒ 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.
211 212 213 |
# File 'lib/vedeu/cursors/cursor.rb', line 211 def oy @oy = @oy < 0 ? 0 : @oy end |
#repository ⇒ Vedeu::Repositories::Repository Originally defined in module Repositories::Model
#visible ⇒ Boolean Also known as: visible? Originally defined in module Toggleable
Returns Whether the toggleable is visible.
#x ⇒ 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 column/character coordinate.
241 242 243 244 245 |
# File 'lib/vedeu/cursors/cursor.rb', line 241 def x @x = (@x < bx) ? bx : @x @x = (@x > bxn) ? bxn : @x @x end |
#y ⇒ 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 row/line coordinate.
248 249 250 251 252 |
# File 'lib/vedeu/cursors/cursor.rb', line 248 def y @y = (@y < by) ? by : @y @y = (@y > byn) ? byn : @y @y end |
Class Method Details
.store(attributes = {}) ⇒ Vedeu::Cursors::Cursor
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.
44 45 46 |
# File 'lib/vedeu/cursors/cursor.rb', line 44 def self.store(attributes = {}) new(attributes).store end |
Instance Method Details
#absent?(variable) ⇒ Boolean Originally defined in module Vedeu::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.
#attributes ⇒ Hash<Symbol => Boolean|Fixnum|String| Vedeu::Cursors::Repository>
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.
73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/vedeu/cursors/cursor.rb', line 73 def attributes { name: @name, ox: ox, oy: oy, repository: @repository, visible: @visible, x: x, y: y, } end |
#coordinate(offset, type) ⇒ Vedeu::Geometry::Coordinate (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.
Determine correct x and y related coordinates.
266 267 268 |
# File 'lib/vedeu/cursors/cursor.rb', line 266 def coordinate(offset, type) Vedeu::Geometry::Coordinate.new(name: name, offset: offset, type: type) end |
#defaults ⇒ Hash<Symbol => Boolean|Fixnum|String| Vedeu::Cursors::Repository> (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 values for a new instance of this class.
274 275 276 277 278 279 280 281 282 283 284 |
# File 'lib/vedeu/cursors/cursor.rb', line 274 def defaults { name: '', ox: 0, oy: 0, repository: Vedeu.cursors, visible: false, x: 1, y: 1, } end |
#demodulize(klass) ⇒ String Originally defined in module Vedeu::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.
#eql?(other) ⇒ Boolean Also known as: ==
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.
An object is equal when its values are the same.
89 90 91 |
# File 'lib/vedeu/cursors/cursor.rb', line 89 def eql?(other) self.class == other.class && name == other.name end |
#escape_sequence ⇒ Vedeu::Models::Escape (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.
287 288 289 |
# File 'lib/vedeu/cursors/cursor.rb', line 287 def escape_sequence Vedeu::Models::Escape.new(position: position, value: visibility) end |
#geometry ⇒ Object (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 geometry for the interface.
259 260 261 |
# File 'lib/vedeu/cursors/cursor.rb', line 259 def geometry @geometry ||= Vedeu.geometries.by_name(name) end |
#hide ⇒ Vedeu::Models::Escape
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.
Hide a named cursor, or without a name, the cursor of the currently focussed interface.
199 200 201 202 203 |
# File 'lib/vedeu/cursors/cursor.rb', line 199 def hide super render end |
#move_down ⇒ Vedeu::Cursors::Cursor
100 101 102 103 104 105 |
# File 'lib/vedeu/cursors/cursor.rb', line 100 def move_down @oy += 1 @y = coordinate(oy, :y).y store_and_refresh end |
#move_left ⇒ Vedeu::Cursors::Cursor
113 114 115 116 117 118 |
# File 'lib/vedeu/cursors/cursor.rb', line 113 def move_left @ox -= 1 @x = coordinate(ox, :x).x store_and_refresh end |
#move_origin ⇒ Vedeu::Cursors::Cursor
126 127 128 129 130 131 132 133 |
# File 'lib/vedeu/cursors/cursor.rb', line 126 def move_origin @x = bx @y = by @ox = 0 @oy = 0 store end |
#move_right ⇒ Vedeu::Cursors::Cursor
141 142 143 144 145 146 |
# File 'lib/vedeu/cursors/cursor.rb', line 141 def move_right @ox += 1 @x = coordinate(ox, :x).x store_and_refresh end |
#move_up ⇒ Vedeu::Cursors::Cursor
154 155 156 157 158 159 |
# File 'lib/vedeu/cursors/cursor.rb', line 154 def move_up @oy -= 1 @y = coordinate(oy, :y).y store_and_refresh end |
#new_attributes(new_y = y, new_x = x, new_oy = oy, new_ox = ox) ⇒ Hash<Symbol => Fixnum> (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.
292 293 294 |
# File 'lib/vedeu/cursors/cursor.rb', line 292 def new_attributes(new_y = y, new_x = x, new_oy = oy, new_ox = ox) attributes.merge!(x: new_x, y: new_y, ox: new_ox, oy: new_oy) end |
#position ⇒ Vedeu::Geometry::Position
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 the position of this cursor.
218 219 220 |
# File 'lib/vedeu/cursors/cursor.rb', line 218 def position @position = Vedeu::Geometry::Position[y, x] end |
#present?(variable) ⇒ Boolean Originally defined in module Vedeu::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.
#render ⇒ Array<Vedeu::Models::Escape>
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.
Renders the cursor.
164 165 166 167 168 |
# File 'lib/vedeu/cursors/cursor.rb', line 164 def render Vedeu.log(type: :output, message: "Refreshing cursor: '#{name}'".freeze) Vedeu.render_output(escape_sequence) end |
#show ⇒ Vedeu::Models::Escape
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.
Show a named cursor, or without a name, the cursor of the currently focussed interface.
234 235 236 237 238 |
# File 'lib/vedeu/cursors/cursor.rb', line 234 def show super render end |
#snake_case(name) ⇒ String Originally defined in module Vedeu::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.
#store_and_refresh ⇒ 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.
This method returns an undefined value.
Store the cursor and refresh the cursor.
299 300 301 302 303 304 305 |
# File 'lib/vedeu/cursors/cursor.rb', line 299 def store_and_refresh store Vedeu.trigger(:_refresh_cursor_, name) self end |
#to_a ⇒ Array<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.
171 172 173 |
# File 'lib/vedeu/cursors/cursor.rb', line 171 def to_a position.to_a end |
#to_s ⇒ String Also known as: to_str
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 an escape sequence to position the cursor and set its visibility. When passed a block, will position the cursor, yield and return the original position.
180 181 182 183 184 |
# File 'lib/vedeu/cursors/cursor.rb', line 180 def to_s return escape_sequence.to_s unless block_given? "#{position}#{yield}#{escape_sequence}".freeze end |
#toggle ⇒ FalseClass|TrueClass Originally defined in module Toggleable
Toggle the visible state and store the model. When the model is hidden, then it is shown, and vice versa.
#visibility ⇒ String (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 escape sequence for setting the visibility of the cursor.
311 312 313 314 315 |
# File 'lib/vedeu/cursors/cursor.rb', line 311 def visibility return Vedeu::EscapeSequences::Esc.show_cursor if visible? Vedeu::EscapeSequences::Esc.hide_cursor end |