Class: Vedeu::Editor::Cursor Private
- Inherits:
-
Object
- Object
- Vedeu::Editor::Cursor
- Extended by:
- Forwardable
- Defined in:
- lib/vedeu/editor/cursor.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Maintains a cursor position within the Document class.
Instance Attribute Summary collapse
- #name ⇒ String|Symbol readonly private
- #ox ⇒ Fixnum
- #oy ⇒ Fixnum
-
#x ⇒ Fixnum
private
The column/character coordinate.
-
#y ⇒ Fixnum
private
The row/line coordinate.
Instance Method Summary collapse
-
#bol ⇒ Vedeu::Editor::Cursor
private
Move the virtual cursor to the beginning of the line.
-
#defaults ⇒ Hash<Symbol => Fixnum|NilClass|String|Symbol>
private
private
Returns the default options/attributes for this class.
-
#down(size = nil) ⇒ Vedeu::Editor::Cursor
private
Move the virtual cursor down by one line.
-
#geometry ⇒ Object
private
private
Returns the geometry for the interface.
-
#initialize(attributes = {}) ⇒ Vedeu::Editor::Cursor
constructor
private
Returns a new instance of Vedeu::Editor::Cursor.
-
#left ⇒ Vedeu::Editor::Cursor
private
Move the virtual cursor to the left.
-
#real_x ⇒ Fixnum
private
private
Return the real x coordinate.
-
#real_y ⇒ Fixnum
private
private
Return the real y coordinate.
-
#refresh ⇒ Vedeu::Editor::Cursor
private
Overwrite the cursor of the same name.
-
#reset! ⇒ Vedeu::Editor::Cursor
private
Move the virtual cursor to the origin (0, 0).
-
#right ⇒ Vedeu::Editor::Cursor
private
Move the virtual cursor to the right.
-
#to_s ⇒ String
private
Return the escape sequence as a string for setting the cursor position and show the cursor.
-
#up(size = nil) ⇒ Vedeu::Editor::Cursor
private
Move the virtual cursor up by one line.
Constructor Details
#initialize(attributes = {}) ⇒ Vedeu::Editor::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::Editor::Cursor.
50 51 52 53 54 |
# File 'lib/vedeu/editor/cursor.rb', line 50 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.
22 23 24 |
# File 'lib/vedeu/editor/cursor.rb', line 22 def name @name end |
#ox ⇒ Fixnum
26 27 28 |
# File 'lib/vedeu/editor/cursor.rb', line 26 def ox @ox end |
#oy ⇒ Fixnum
30 31 32 |
# File 'lib/vedeu/editor/cursor.rb', line 30 def oy @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.
34 |
# File 'lib/vedeu/editor/cursor.rb', line 34 attr_writer :x |
#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.
38 |
# File 'lib/vedeu/editor/cursor.rb', line 38 attr_writer :y |
Instance Method Details
#bol ⇒ Vedeu::Editor::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.
Move the virtual cursor to the beginning of the line.
59 60 61 62 63 64 |
# File 'lib/vedeu/editor/cursor.rb', line 59 def bol @ox = 0 @x = 0 self end |
#defaults ⇒ Hash<Symbol => Fixnum|NilClass|String|Symbol> (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 default options/attributes for this class.
175 176 177 178 179 180 181 182 183 |
# File 'lib/vedeu/editor/cursor.rb', line 175 def defaults { name: '', ox: 0, oy: 0, x: 0, y: 0, } end |
#down(size = nil) ⇒ Vedeu::Editor::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.
Move the virtual cursor down by one line.
70 71 72 73 74 75 |
# File 'lib/vedeu/editor/cursor.rb', line 70 def down(size = nil) @y += 1 @x = size if size && x > size self 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.
168 169 170 |
# File 'lib/vedeu/editor/cursor.rb', line 168 def geometry @border ||= Vedeu.geometries.by_name(name) end |
#left ⇒ Vedeu::Editor::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.
Move the virtual cursor to the left.
80 81 82 83 84 85 |
# File 'lib/vedeu/editor/cursor.rb', line 80 def left @ox -= 1 unless @ox == 0 @x -= 1 self end |
#real_x ⇒ 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.
Return the real x coordinate.
195 196 197 |
# File 'lib/vedeu/editor/cursor.rb', line 195 def real_x (bx + x) - ox end |
#real_y ⇒ 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.
Return the real y coordinate.
188 189 190 |
# File 'lib/vedeu/editor/cursor.rb', line 188 def real_y (by + y) - oy end |
#refresh ⇒ Vedeu::Editor::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.
GL 2015-10-02 Should ox/oy be 0; or set to @ox/@oy?
Overwrite the cursor of the same name. This ensure that on refresh the cursor stays in the correct position for the document being edited.
93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/vedeu/editor/cursor.rb', line 93 def refresh Vedeu::Cursors::Cursor.store(name: name, x: real_x, y: real_y, ox: 0, oy: 0, visible: true) Vedeu.trigger(:_refresh_cursor_, name) self end |
#reset! ⇒ Vedeu::Editor::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.
Move the virtual cursor to the origin (0, 0).
109 110 111 112 113 114 115 116 |
# File 'lib/vedeu/editor/cursor.rb', line 109 def reset! @x = 0 @y = 0 @ox = 0 @oy = 0 self end |
#right ⇒ Vedeu::Editor::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.
Move the virtual cursor to the right.
121 122 123 124 125 |
# File 'lib/vedeu/editor/cursor.rb', line 121 def right @x += 1 self end |
#to_s ⇒ 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.
Return the escape sequence as a string for setting the cursor position and show the cursor.
131 132 133 |
# File 'lib/vedeu/editor/cursor.rb', line 131 def to_s "\e[#{real_y};#{real_x}H\e[?25h".freeze end |
#up(size = nil) ⇒ Vedeu::Editor::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.
Move the virtual cursor up by one line.
139 140 141 142 143 144 145 |
# File 'lib/vedeu/editor/cursor.rb', line 139 def up(size = nil) @oy -= 1 unless @oy == 0 @y -= 1 @x = size if size && x > size self end |