Class: Vedeu::Cursors::Cursor
- Inherits:
-
Object
- Object
- Vedeu::Cursors::Cursor
- Extended by:
- Forwardable
- Includes:
- Model, Toggleable
- Defined in:
- lib/vedeu/cursors/cursor.rb,
lib/vedeu/cursors/repository.rb
Overview
Repository
Instance Attribute Summary collapse
- #attributes ⇒ Hash readonly
- #name ⇒ String readonly
- #ox ⇒ Fixnum
- #oy ⇒ Fixnum
- #state ⇒ Boolean|Symbol readonly
-
#x ⇒ Fixnum
The column/character coordinate.
-
#y ⇒ Fixnum
The row/line coordinate.
Attributes included from Toggleable
Attributes included from Model
Instance Method Summary collapse
- #border ⇒ Object private
- #coordinate ⇒ Vedeu::Geometry::Coordinate private
-
#defaults ⇒ Hash
private
The default values for a new instance of this class.
-
#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.
-
#position ⇒ Vedeu::Geometry::Position
Return the position of this cursor.
-
#render ⇒ Array<Vedeu::Models::Escape>
Renders the cursor.
-
#reposition(new_y, new_x) ⇒ 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.
-
#to_s ⇒ String
(also: #to_str)
Returns an escape sequence to position the cursor and set its visibility.
-
#toggle ⇒ Vedeu::Models::Escape
Toggle the visibility of the cursor with the given name.
-
#visibility ⇒ String
private
Returns the escape sequence for setting the visibility of the cursor.
Methods included from Toggleable
Methods included from Model
#deputy, #dsl_class, included, #store
Methods included from Vedeu::Common
#demodulize, #present?, #snake_case
Constructor Details
#initialize(attributes = {}) ⇒ Vedeu::Cursors::Cursor
Returns a new instance of Vedeu::Cursors::Cursor.
64 65 66 67 68 69 70 |
# File 'lib/vedeu/cursors/cursor.rb', line 64 def initialize(attributes = {}) @attributes = defaults.merge!(attributes) @attributes.each do |key, value| instance_variable_set("@#{key}", value) end end |
Instance Attribute Details
#attributes ⇒ Hash (readonly)
22 23 24 |
# File 'lib/vedeu/cursors/cursor.rb', line 22 def attributes @attributes end |
#name ⇒ String (readonly)
26 27 28 |
# File 'lib/vedeu/cursors/cursor.rb', line 26 def name @name end |
#ox ⇒ Fixnum
189 190 191 192 |
# File 'lib/vedeu/cursors/cursor.rb', line 189 def ox @ox = 0 if @ox < 0 @ox end |
#oy ⇒ Fixnum
195 196 197 198 |
# File 'lib/vedeu/cursors/cursor.rb', line 195 def oy @oy = 0 if @oy < 0 @oy end |
#state ⇒ Boolean|Symbol (readonly)
38 39 40 |
# File 'lib/vedeu/cursors/cursor.rb', line 38 def state @state end |
#x ⇒ Fixnum
Returns The column/character coordinate.
237 238 239 240 241 242 243 244 |
# File 'lib/vedeu/cursors/cursor.rb', line 237 def x @x = bx if @x < bx @x = bxn if @x > bxn @attributes[:x] = @x @x end |
#y ⇒ Fixnum
Returns The row/line coordinate.
247 248 249 250 251 252 253 254 |
# File 'lib/vedeu/cursors/cursor.rb', line 247 def y @y = by if @y < by @y = byn if @y > byn @attributes[:y] = @y @y end |
Instance Method Details
#border ⇒ Object (private)
259 260 261 |
# File 'lib/vedeu/cursors/cursor.rb', line 259 def border @border ||= Vedeu.borders.by_name(name) end |
#coordinate ⇒ Vedeu::Geometry::Coordinate (private)
264 265 266 |
# File 'lib/vedeu/cursors/cursor.rb', line 264 def coordinate @coordinate ||= Vedeu::Geometry::Coordinate.new(name, oy, ox) end |
#defaults ⇒ Hash (private)
The default values for a new instance of this class.
271 272 273 274 275 276 277 278 279 280 281 |
# File 'lib/vedeu/cursors/cursor.rb', line 271 def defaults { name: '', ox: 0, oy: 0, repository: Vedeu.cursors, visible: false, x: 1, y: 1, } end |
#hide ⇒ Vedeu::Models::Escape
Hide a named cursor, or without a name, the cursor of the currently focussed interface.
182 183 184 185 186 |
# File 'lib/vedeu/cursors/cursor.rb', line 182 def hide super render end |
#move_down ⇒ Vedeu::Cursors::Cursor
Moves the cursor down by one row.
75 76 77 78 79 80 81 82 83 84 |
# File 'lib/vedeu/cursors/cursor.rb', line 75 def move_down @oy += 1 @attributes = attributes.merge!(x: x, y: coordinate.y_position, ox: ox, oy: oy) Vedeu::Cursors::Cursor.new(@attributes).store end |
#move_left ⇒ Vedeu::Cursors::Cursor
Moves the cursor left by one column.
89 90 91 92 93 94 95 96 97 98 |
# File 'lib/vedeu/cursors/cursor.rb', line 89 def move_left @ox -= 1 @attributes = attributes.merge!(x: coordinate.x_position, y: y, ox: ox, oy: oy) Vedeu::Cursors::Cursor.new(@attributes).store end |
#move_origin ⇒ Vedeu::Cursors::Cursor
Moves the cursor to the top left of the named interface.
103 104 105 106 107 |
# File 'lib/vedeu/cursors/cursor.rb', line 103 def move_origin @attributes = attributes.merge!(x: bx, y: by, ox: 0, oy: 0) Vedeu::Cursors::Cursor.new(@attributes).store end |
#move_right ⇒ Vedeu::Cursors::Cursor
Moves the cursor right by one column.
112 113 114 115 116 117 118 119 120 121 |
# File 'lib/vedeu/cursors/cursor.rb', line 112 def move_right @ox += 1 @attributes = attributes.merge!(x: coordinate.x_position, y: y, ox: ox, oy: oy) Vedeu::Cursors::Cursor.new(@attributes).store end |
#move_up ⇒ Vedeu::Cursors::Cursor
Moves the cursor up by one row.
126 127 128 129 130 131 132 133 134 135 |
# File 'lib/vedeu/cursors/cursor.rb', line 126 def move_up @oy -= 1 @attributes = attributes.merge!(x: x, y: coordinate.y_position, ox: ox, oy: oy) Vedeu::Cursors::Cursor.new(@attributes).store end |
#position ⇒ Vedeu::Geometry::Position
Return the position of this cursor.
203 204 205 |
# File 'lib/vedeu/cursors/cursor.rb', line 203 def position @position = Vedeu::Geometry::Position[y, x] end |
#render ⇒ Array<Vedeu::Models::Escape>
Renders the cursor.
140 141 142 |
# File 'lib/vedeu/cursors/cursor.rb', line 140 def render Vedeu::Output::Output.render(visibility) end |
#reposition(new_y, new_x) ⇒ Vedeu::Cursors::Cursor
Arbitrarily move the cursor to a given position.
149 150 151 152 153 154 155 156 |
# File 'lib/vedeu/cursors/cursor.rb', line 149 def reposition(new_y, new_x) @attributes = attributes.merge!(x: coordinate.x_position, y: coordinate.y_position, ox: new_x, oy: new_y) Vedeu::Cursors::Cursor.new(@attributes).store end |
#show ⇒ Vedeu::Models::Escape
Show a named cursor, or without a name, the cursor of the currently focussed interface.
214 215 216 217 218 |
# File 'lib/vedeu/cursors/cursor.rb', line 214 def show super render 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.
163 164 165 166 167 168 169 170 171 |
# File 'lib/vedeu/cursors/cursor.rb', line 163 def to_s if block_given? "#{position}#{yield}#{visibility}" else "#{visibility}" end end |
#toggle ⇒ Vedeu::Models::Escape
Toggle the visibility of the cursor with the given name.
226 227 228 229 230 231 232 233 234 |
# File 'lib/vedeu/cursors/cursor.rb', line 226 def toggle if visible? hide else show end end |
#visibility ⇒ String (private)
Returns the escape sequence for setting the visibility of the cursor.
287 288 289 290 291 |
# File 'lib/vedeu/cursors/cursor.rb', line 287 def visibility value = visible? ? Vedeu::Esc.show_cursor : Vedeu::Esc.hide_cursor Vedeu::Models::Escape.new(position: position, value: value) end |