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
-
#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 ⇒ Object
private
private
Returns the geometry for the interface.
-
#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
- #new_attributes(new_y = y, new_x = x, new_oy = oy, new_ox = ox) ⇒ Hash<Symbol => Fixnum> private 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
Methods included from Vedeu::Common
#absent?, #array?, #boolean, #boolean?, #empty_value?, #escape?, #falsy?, #hash?, #line_model?, #numeric?, #positionable?, #present?, #snake_case, #stream_model?, #string?, #symbol?, #truthy?, #view_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 ⇒ 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.
179 180 181 |
# File 'lib/vedeu/cursors/cursor.rb', line 179 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.
184 185 186 |
# File 'lib/vedeu/cursors/cursor.rb', line 184 def oy @oy = @oy < 0 ? 0 : @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.
227 228 229 230 231 |
# File 'lib/vedeu/cursors/cursor.rb', line 227 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.
234 235 236 237 238 239 240 241 242 243 244 |
# File 'lib/vedeu/cursors/cursor.rb', line 234 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.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.
247 248 249 |
# File 'lib/vedeu/cursors/cursor.rb', line 247 def escape_sequence Vedeu::Cells::Cursor.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.
220 221 222 |
# File 'lib/vedeu/cursors/cursor.rb', line 220 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 |
#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.
252 253 254 |
# File 'lib/vedeu/cursors/cursor.rb', line 252 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::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.
260 261 262 263 264 |
# File 'lib/vedeu/cursors/cursor.rb', line 260 def visibility return Vedeu.esc.show_cursor if visible? Vedeu.esc.hide_cursor end |