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 ⇒ NilClass|Symbol|String
readonly
private
The name of the model, the target model or the name of the associated model.
- #ox ⇒ Fixnum private
- #oy ⇒ Fixnum private
-
#x ⇒ Fixnum
private
The column/character coordinate.
-
#y ⇒ Fixnum
private
The row/line coordinate.
Attributes included from Toggleable
Attributes included from Repositories::Model
Instance Method Summary collapse
- #attributes ⇒ Hash<Symbol => Boolean|Fixnum|String| Vedeu::Cursors::Repository> private
-
#coordinate(offset, type) ⇒ Vedeu::Cursors::Coordinate
private
private
Determine correct x and y related coordinates.
-
#defaults ⇒ Hash<Symbol => void>
private
private
The default options/attributes for a new instance of this class.
-
#eql?(other) ⇒ Boolean
(also: #==)
private
An object is equal when its values are the same.
- #escape_sequence ⇒ Vedeu::Cells::Cursor private private
-
#geometry ⇒ Vedeu::Geometries::Geometry
private
private
Returns the named geometry from the geometries repository.
-
#hide ⇒ Vedeu::Cells::Cursor
private
-
#initialize(attributes = {}) ⇒ Vedeu::Cursors::Cursor
constructor
private
Returns a new instance of Vedeu::Cursors::Cursor.
- #inspect ⇒ String private
-
#move_down(offset = 1) ⇒ Vedeu::Cursors::Cursor
private
-
#move_left(offset = 1) ⇒ Vedeu::Cursors::Cursor
private
-
#move_origin ⇒ Vedeu::Cursors::Cursor
private
-
#move_right(offset = 1) ⇒ Vedeu::Cursors::Cursor
private
-
#move_up(offset = 1) ⇒ Vedeu::Cursors::Cursor
private
-
#position ⇒ Vedeu::Geometries::Position
private
Return the position of this cursor.
-
#render ⇒ Array<Vedeu::Cells::Cursor>
private
Renders the cursor.
-
#show ⇒ Vedeu::Cells::Cursor
private
- #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.
-
#visibility ⇒ String
private
private
Returns the escape sequence for setting the visibility of the cursor.
Methods included from Toggleable
Methods included from Repositories::Model
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 ⇒ NilClass|Symbol|String (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.
Returns The name of the model, the target model or the name of the associated model.
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.
179 180 181 |
# File 'lib/vedeu/cursors/cursor.rb', line 179 def ox @ox = @ox < 1 ? 1 : @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.
184 185 186 |
# File 'lib/vedeu/cursors/cursor.rb', line 184 def oy @oy = @oy < 1 ? 1 : @oy end |
#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.
206 207 208 |
# File 'lib/vedeu/cursors/cursor.rb', line 206 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.
211 212 213 |
# File 'lib/vedeu/cursors/cursor.rb', line 211 def y @y = Vedeu::Point.coerce(value: @y, min: by, max: byn).value end |
Instance Method Details
#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 |
#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.
225 226 227 228 229 |
# File 'lib/vedeu/cursors/cursor.rb', line 225 def coordinate(offset, type) Vedeu::Cursors::Coordinate.new(geometry: geometry, offset: offset, type: type) end |
#defaults ⇒ Hash<Symbol => 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.
The default options/attributes for a new instance of this class.
232 233 234 235 236 237 238 239 240 241 242 |
# File 'lib/vedeu/cursors/cursor.rb', line 232 def defaults { name: nil, ox: 1, oy: 1, 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.equal?(other.class) && name == other.name end |
#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.
245 246 247 |
# File 'lib/vedeu/cursors/cursor.rb', line 245 def escape_sequence Vedeu::Cells::Cursor.new(position: position, value: visibility) end |
#geometry ⇒ Vedeu::Geometries::Geometry (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 named geometry from the geometries repository.
218 219 220 |
# File 'lib/vedeu/cursors/cursor.rb', line 218 def geometry @_geometry ||= Vedeu.geometries.by_name(name) end |
#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.
170 171 172 173 174 175 176 |
# File 'lib/vedeu/cursors/cursor.rb', line 170 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 "name: #{name.inspect} x: #{x} y: #{y} ox: #{ox} oy: #{oy} " \ "visible: #{visible}" end |
#move_down(offset = 1) ⇒ 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.
98 99 100 101 102 103 |
# File 'lib/vedeu/cursors/cursor.rb', line 98 def move_down(offset = 1) @oy += offset || 1 @y = coordinate(oy, :y).y self end |
#move_left(offset = 1) ⇒ 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.
107 108 109 110 111 112 |
# File 'lib/vedeu/cursors/cursor.rb', line 107 def move_left(offset = 1) @ox -= offset || 1 @x = coordinate(ox, :x).x self end |
#move_origin ⇒ 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.
116 117 118 119 120 121 122 123 |
# File 'lib/vedeu/cursors/cursor.rb', line 116 def move_origin @x = bx @y = by @ox = 0 @oy = 0 store end |
#move_right(offset = 1) ⇒ 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.
127 128 129 130 131 132 |
# File 'lib/vedeu/cursors/cursor.rb', line 127 def move_right(offset = 1) @ox += offset || 1 @x = coordinate(ox, :x).x self end |
#move_up(offset = 1) ⇒ 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.
136 137 138 139 140 141 |
# File 'lib/vedeu/cursors/cursor.rb', line 136 def move_up(offset = 1) @oy -= offset || 1 @y = coordinate(oy, :y).y self end |
#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.
191 192 193 |
# File 'lib/vedeu/cursors/cursor.rb', line 191 def position @position = Vedeu::Geometries::Position.new(y, x) end |
#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.
146 147 148 |
# File 'lib/vedeu/cursors/cursor.rb', line 146 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.
197 198 199 200 201 202 203 |
# File 'lib/vedeu/cursors/cursor.rb', line 197 def show super Vedeu.log(type: :cursor, message: "Showing cursor: '#{name}'") render 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.
151 152 153 |
# File 'lib/vedeu/cursors/cursor.rb', line 151 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.
161 162 163 164 165 |
# File 'lib/vedeu/cursors/cursor.rb', line 161 def to_s(&block) return escape_sequence.to_s unless block_given? "#{position}#{yield}#{escape_sequence}" end |
#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.
253 254 255 256 257 |
# File 'lib/vedeu/cursors/cursor.rb', line 253 def visibility return Vedeu.esc.show_cursor if visible? Vedeu.esc.hide_cursor end |