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.
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
-
#become(klass, attributes) ⇒ Class
included
from Vedeu::Common
private
Converts one class into another.
-
#boolean(value) ⇒ Boolean
included
from Vedeu::Common
private
Returns a boolean indicating the value was a boolean.
-
#boolean?(value) ⇒ Boolean
included
from Vedeu::Common
private
Returns a boolean indicating whether the value is a Boolean.
-
#coordinate(offset, type) ⇒ Vedeu::Cursors::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.
-
#eql?(other) ⇒ Boolean
(also: #==)
private
An object is equal when its values are the same.
-
#escape?(value) ⇒ Boolean
included
from Vedeu::Common
private
Returns a boolean indicating whether the value is an escape sequence object (e.g. Vedeu::Cells::Escape.).
- #escape_sequence ⇒ Vedeu::Cells::Cursor private private
-
#falsy?(value) ⇒ Boolean
included
from Vedeu::Common
private
Returns a boolean indicating whether the value should be considered false.
-
#geometry ⇒ Object
private
private
Returns the geometry for the interface.
-
#hash?(value) ⇒ Boolean
included
from Vedeu::Common
private
Returns a boolean indicating whether the value is a Hash.
-
#hide ⇒ Vedeu::Cells::Cursor
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.
- #inspect ⇒ String private
-
#line_model? ⇒ Boolean
included
from Vedeu::Common
private
Returns a boolean indicating the model is a Views::Line.
-
#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
-
#numeric?(value) ⇒ Boolean
included
from Vedeu::Common
private
Returns a boolean indicating whether the value is a Fixnum.
-
#position ⇒ Vedeu::Geometries::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::Cells::Cursor>
private
Renders the cursor.
-
#show ⇒ Vedeu::Cells::Cursor
private
Show a named cursor, or without a name, the cursor of the currently focussed interface.
-
#snake_case(klass) ⇒ String
included
from Vedeu::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 Vedeu::Common
private
Returns a boolean indicating the model is a Views::Stream.
-
#string?(value) ⇒ Boolean
included
from Vedeu::Common
private
Returns a boolean indicating whether the value is a Fixnum.
- #to_a ⇒ Array<Fixnum> private
-
#to_s(&block) ⇒ String
(also: #to_str)
private
Returns an escape sequence to position the cursor and set its visibility.
-
#toggle ⇒ Boolean
included
from Toggleable
Toggle the visible state and store the model.
-
#truthy?(value) ⇒ Boolean
included
from Vedeu::Common
private
Returns a boolean indicating whether the value should be considered true.
-
#view_model? ⇒ Boolean
included
from Vedeu::Common
private
Returns a boolean indicating the model is a Views::View.
-
#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.
61 62 63 64 65 |
# File 'lib/vedeu/cursors/cursor.rb', line 61 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.
26 27 28 |
# File 'lib/vedeu/cursors/cursor.rb', line 26 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.
209 210 211 |
# File 'lib/vedeu/cursors/cursor.rb', line 209 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.
214 215 216 |
# File 'lib/vedeu/cursors/cursor.rb', line 214 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.
246 247 248 |
# File 'lib/vedeu/cursors/cursor.rb', line 246 def x @x = Vedeu::Point.coerce(value: @x, min: bx, max: bxn).value 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.
251 252 253 |
# File 'lib/vedeu/cursors/cursor.rb', line 251 def y @y = Vedeu::Point.coerce(value: @y, min: by, max: byn).value 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.
69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/vedeu/cursors/cursor.rb', line 69 def attributes { name: @name, ox: ox, oy: oy, repository: @repository, visible: @visible, x: x, y: y, } end |
#become(klass, attributes) ⇒ Class 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 one class into another.
#boolean(value) ⇒ 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 the value was a boolean.
#boolean?(value) ⇒ 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 the value is a Boolean.
#coordinate(offset, type) ⇒ Vedeu::Cursors::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.
267 268 269 270 271 |
# File 'lib/vedeu/cursors/cursor.rb', line 267 def coordinate(offset, type) Vedeu::Cursors::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.
277 278 279 280 281 282 283 284 285 286 287 |
# File 'lib/vedeu/cursors/cursor.rb', line 277 def defaults { name: '', ox: 0, oy: 0, repository: Vedeu.cursors, visible: false, x: 1, y: 1, } end |
#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.
85 86 87 |
# File 'lib/vedeu/cursors/cursor.rb', line 85 def eql?(other) self.class == other.class && name == other.name end |
#escape?(value) ⇒ 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 the value is an escape sequence object (e.g. Vedeu::Cells::Escape.)
#escape_sequence ⇒ Vedeu::Cells::Cursor (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.
290 291 292 |
# File 'lib/vedeu/cursors/cursor.rb', line 290 def escape_sequence Vedeu::Cells::Cursor.new(position: position, value: visibility) end |
#falsy?(value) ⇒ 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 the value should be considered false.
#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.
260 261 262 |
# File 'lib/vedeu/cursors/cursor.rb', line 260 def geometry @geometry ||= Vedeu.geometries.by_name(name) end |
#hash?(value) ⇒ 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 the value is a Hash.
#hide ⇒ Vedeu::Cells::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.
Hide a named cursor, or without a name, the cursor of the currently focussed interface.
200 201 202 203 204 205 206 |
# File 'lib/vedeu/cursors/cursor.rb', line 200 def hide super Vedeu.log(type: :cursor, message: "Hiding cursor: '#{name}'") render end |
#inspect ⇒ String
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.
91 92 93 94 |
# File 'lib/vedeu/cursors/cursor.rb', line 91 def inspect "<#{self.class.name} name:'#{name}', x:#{x}, y:#{y}, ox:#{ox}, " \ "oy:#{oy}, visible:#{visible}>" end |
#line_model? ⇒ 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 the model is a Views::Line.
#move_down ⇒ Vedeu::Cursors::Cursor
102 103 104 105 106 107 |
# File 'lib/vedeu/cursors/cursor.rb', line 102 def move_down @oy += 1 @y = coordinate(oy, :y).y self end |
#move_left ⇒ Vedeu::Cursors::Cursor
115 116 117 118 119 120 |
# File 'lib/vedeu/cursors/cursor.rb', line 115 def move_left @ox -= 1 @x = coordinate(ox, :x).x self end |
#move_origin ⇒ Vedeu::Cursors::Cursor
128 129 130 131 132 133 134 135 |
# File 'lib/vedeu/cursors/cursor.rb', line 128 def move_origin @x = bx @y = by @ox = 0 @oy = 0 store end |
#move_right ⇒ Vedeu::Cursors::Cursor
143 144 145 146 147 148 |
# File 'lib/vedeu/cursors/cursor.rb', line 143 def move_right @ox += 1 @x = coordinate(ox, :x).x self end |
#move_up ⇒ Vedeu::Cursors::Cursor
156 157 158 159 160 161 |
# File 'lib/vedeu/cursors/cursor.rb', line 156 def move_up @oy -= 1 @y = coordinate(oy, :y).y self 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.
295 296 297 |
# File 'lib/vedeu/cursors/cursor.rb', line 295 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 |
#numeric?(value) ⇒ 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 the value is a Fixnum.
#position ⇒ Vedeu::Geometries::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.
221 222 223 |
# File 'lib/vedeu/cursors/cursor.rb', line 221 def position @position = Vedeu::Geometries::Position.coerce([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::Cells::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.
Renders the cursor.
166 167 168 |
# File 'lib/vedeu/cursors/cursor.rb', line 166 def render Vedeu.render_output(escape_sequence) end |
#show ⇒ Vedeu::Cells::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.
Show a named cursor, or without a name, the cursor of the currently focussed interface.
237 238 239 240 241 242 243 |
# File 'lib/vedeu/cursors/cursor.rb', line 237 def show super Vedeu.log(type: :cursor, message: "Showing cursor: '#{name}'") render end |
#snake_case(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.
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 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 the model is a Views::Stream.
#string?(value) ⇒ 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 the value is a Fixnum.
#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(&block) ⇒ 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.
181 182 183 184 185 |
# File 'lib/vedeu/cursors/cursor.rb', line 181 def to_s(&block) return escape_sequence.to_s unless block_given? "#{position}#{yield}#{escape_sequence}" end |
#toggle ⇒ Boolean 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.
#truthy?(value) ⇒ 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 the value should be considered true.
#view_model? ⇒ 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 the model is a Views::View.
#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.
303 304 305 306 307 |
# File 'lib/vedeu/cursors/cursor.rb', line 303 def visibility return Vedeu.esc.show_cursor if visible? Vedeu.esc.hide_cursor end |