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
- #ox ⇒ Fixnum
- #oy ⇒ Fixnum
- #repository ⇒ Vedeu::Repositories::Repository included from Repositories::Model
-
#visible ⇒ Boolean
(also: #visible?)
included
from Toggleable
Whether the toggleable is visible.
-
#x ⇒ Fixnum
The column/character coordinate.
-
#y ⇒ Fixnum
The row/line coordinate.
Class Method Summary collapse
Instance Method Summary collapse
-
#absent?(variable) ⇒ Boolean
included
from Vedeu::Common
Returns a boolean indicating whether a variable is nil or empty.
- #attributes ⇒ Hash
- #border ⇒ Object private
-
#coordinate(offset, type) ⇒ Vedeu::Geometry::Coordinate
private
Determine correct x and y related coordinates.
-
#defaults ⇒ Hash
private
The default values for a new instance of this class.
-
#demodulize(klass) ⇒ String
included
from Vedeu::Common
Removes the module part from the expression in the string.
-
#deputy(client = nil) ⇒ void
included
from Repositories::Model
Returns a DSL instance responsible for defining the DSL methods of this model.
-
#dsl_class ⇒ String
included
from Repositories::Model
private
Returns the DSL class name responsible for this model.
-
#eql?(other) ⇒ Boolean
(also: #==)
An object is equal when its values are the same.
- #escape_sequence ⇒ Vedeu::Models::Escape private
-
#hide ⇒ Vedeu::Models::Escape
Hide a named cursor, or without a name, the cursor of the currently focussed interface.
-
#initialize(attributes = {}) ⇒ Vedeu::Cursors::Cursor
constructor
Returns a new instance of Vedeu::Cursors::Cursor.
-
#move_down ⇒ Vedeu::Cursors::Cursor
Moves the cursor down by one row.
-
#move_left ⇒ Vedeu::Cursors::Cursor
Moves the cursor left by one column.
-
#move_origin ⇒ Vedeu::Cursors::Cursor
Moves the cursor to the top left of the named interface.
-
#move_right ⇒ Vedeu::Cursors::Cursor
Moves the cursor right by one column.
-
#move_up ⇒ Vedeu::Cursors::Cursor
Moves the cursor up by one row.
- #new_attributes(new_y = y, new_x = x, new_oy = oy, new_ox = ox) ⇒ Hash private
-
#position ⇒ Vedeu::Geometry::Position
Return the position of this cursor.
-
#present?(variable) ⇒ Boolean
included
from Vedeu::Common
Returns a boolean indicating whether a variable has a useful value.
-
#render ⇒ Array<Vedeu::Models::Escape>
Renders the cursor.
-
#reposition(new_oy, new_ox) ⇒ Vedeu::Cursors::Cursor
Arbitrarily move the cursor to a given position.
-
#show ⇒ Vedeu::Models::Escape
Show a named cursor, or without a name, the cursor of the currently focussed interface.
-
#snake_case(name) ⇒ String
included
from Vedeu::Common
Converts a class name to a lowercase snake case string.
-
#store ⇒ void
included
from Repositories::Model
The model instance stored in the repository.
- #to_a ⇒ Array<Fixnum>
-
#to_s ⇒ String
(also: #to_str)
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
Returns the escape sequence for setting the visibility of the cursor.
Constructor Details
#initialize(attributes = {}) ⇒ Vedeu::Cursors::Cursor
Returns a new instance of Vedeu::Cursors::Cursor.
62 63 64 65 66 |
# File 'lib/vedeu/cursors/cursor.rb', line 62 def initialize(attributes = {}) defaults.merge!(attributes).each do |key, value| instance_variable_set("@#{key}", value) end end |
Instance Attribute Details
#name ⇒ String|Symbol (readonly)
22 23 24 |
# File 'lib/vedeu/cursors/cursor.rb', line 22 def name @name end |
#ox ⇒ Fixnum
214 215 216 |
# File 'lib/vedeu/cursors/cursor.rb', line 214 def ox @ox < 0 ? 0 : @ox end |
#oy ⇒ Fixnum
219 220 221 |
# File 'lib/vedeu/cursors/cursor.rb', line 219 def 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
Returns The column/character coordinate.
247 248 249 250 251 |
# File 'lib/vedeu/cursors/cursor.rb', line 247 def x @x = (@x < bx) ? bx : @x @x = (@x > bxn) ? bxn : @x @x end |
#y ⇒ Fixnum
Returns The row/line coordinate.
254 255 256 257 258 |
# File 'lib/vedeu/cursors/cursor.rb', line 254 def y @y = (@y < by) ? by : @y @y = (@y > byn) ? byn : @y @y end |
Class Method Details
.store(attributes = {}) ⇒ Vedeu::Cursors::Cursor
42 43 44 |
# File 'lib/vedeu/cursors/cursor.rb', line 42 def self.store(attributes = {}) new(attributes).store end |
Instance Method Details
#absent?(variable) ⇒ Boolean Originally defined in module Vedeu::Common
Returns a boolean indicating whether a variable is nil or empty.
#attributes ⇒ Hash
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 |
#border ⇒ Object (private)
263 264 265 |
# File 'lib/vedeu/cursors/cursor.rb', line 263 def border @border ||= Vedeu.borders.by_name(name) end |
#coordinate(offset, type) ⇒ Vedeu::Geometry::Coordinate (private)
Determine correct x and y related coordinates.
270 271 272 |
# File 'lib/vedeu/cursors/cursor.rb', line 270 def coordinate(offset, type) Vedeu::Geometry::Coordinate.new(name: name, offset: offset, type: type) end |
#defaults ⇒ Hash (private)
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 |
#demodulize(klass) ⇒ String Originally defined in module Vedeu::Common
Removes the module part from the expression in the string.
#deputy(client = nil) ⇒ void Originally defined in module Repositories::Model
This method returns an undefined value.
Returns a DSL instance responsible for defining the DSL methods of this model.
#dsl_class ⇒ String (private) Originally defined in module Repositories::Model
Returns the DSL class name responsible for this model.
#eql?(other) ⇒ Boolean Also known as: ==
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_sequence ⇒ Vedeu::Models::Escape (private)
290 291 292 |
# File 'lib/vedeu/cursors/cursor.rb', line 290 def escape_sequence Vedeu::Models::Escape.new(position: position, value: visibility) end |
#hide ⇒ Vedeu::Models::Escape
Hide a named cursor, or without a name, the cursor of the currently focussed interface.
207 208 209 210 211 |
# File 'lib/vedeu/cursors/cursor.rb', line 207 def hide super render end |
#move_down ⇒ Vedeu::Cursors::Cursor
96 97 98 99 100 101 |
# File 'lib/vedeu/cursors/cursor.rb', line 96 def move_down @oy += 1 @y = coordinate(oy, :y).y store end |
#move_left ⇒ Vedeu::Cursors::Cursor
109 110 111 112 113 114 |
# File 'lib/vedeu/cursors/cursor.rb', line 109 def move_left @ox -= 1 @x = coordinate(ox, :x).x store end |
#move_origin ⇒ Vedeu::Cursors::Cursor
122 123 124 125 126 127 128 129 |
# File 'lib/vedeu/cursors/cursor.rb', line 122 def move_origin @x = bx @y = by @ox = 0 @oy = 0 store end |
#move_right ⇒ Vedeu::Cursors::Cursor
137 138 139 140 141 142 |
# File 'lib/vedeu/cursors/cursor.rb', line 137 def move_right @ox += 1 @x = coordinate(ox, :x).x store end |
#move_up ⇒ Vedeu::Cursors::Cursor
150 151 152 153 154 155 |
# File 'lib/vedeu/cursors/cursor.rb', line 150 def move_up @oy -= 1 @y = coordinate(oy, :y).y store end |
#new_attributes(new_y = y, new_x = x, new_oy = oy, new_ox = ox) ⇒ Hash (private)
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 |
#position ⇒ Vedeu::Geometry::Position
Return the position of this cursor.
226 227 228 |
# File 'lib/vedeu/cursors/cursor.rb', line 226 def position @position = Vedeu::Geometry::Position[y, x] end |
#present?(variable) ⇒ Boolean Originally defined in module Vedeu::Common
Returns a boolean indicating whether a variable has a useful value.
#render ⇒ Array<Vedeu::Models::Escape>
Renders the cursor.
160 161 162 163 164 |
# File 'lib/vedeu/cursors/cursor.rb', line 160 def render Vedeu.log(message: "Refreshing cursor: '#{name}'".freeze) Vedeu.render_output(escape_sequence) end |
#reposition(new_oy, new_ox) ⇒ Vedeu::Cursors::Cursor
Arbitrarily move the cursor to a given position.
171 172 173 174 175 176 177 178 |
# File 'lib/vedeu/cursors/cursor.rb', line 171 def reposition(new_oy, new_ox) @oy = new_oy @ox = new_ox @y = coordinate(oy, :y).y @x = coordinate(ox, :x).x store end |
#show ⇒ Vedeu::Models::Escape
Show a named cursor, or without a name, the cursor of the currently focussed interface.
240 241 242 243 244 |
# File 'lib/vedeu/cursors/cursor.rb', line 240 def show super render end |
#snake_case(name) ⇒ String Originally defined in module Vedeu::Common
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.
#to_a ⇒ Array<Fixnum>
181 182 183 |
# File 'lib/vedeu/cursors/cursor.rb', line 181 def to_a position.to_a end |
#to_s ⇒ String Also known as: to_str
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.
190 191 192 193 194 |
# File 'lib/vedeu/cursors/cursor.rb', line 190 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)
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::EscapeSequences::Esc.show_cursor if visible? Vedeu::EscapeSequences::Esc.hide_cursor end |