Class: Vedeu::Editor::Cursor
- Inherits:
-
Object
- Object
- Vedeu::Editor::Cursor
- Extended by:
- Forwardable
- Defined in:
- lib/vedeu/editor/cursor.rb
Overview
Maintains a cursor position within the Document class.
Instance Attribute Summary collapse
- #name ⇒ String|Symbol readonly
- #ox ⇒ Fixnum
- #oy ⇒ Fixnum
-
#x ⇒ Fixnum
The column/character coordinate.
-
#y ⇒ Fixnum
The row/line coordinate.
Instance Method Summary collapse
-
#bol ⇒ Vedeu::Editor::Cursor
Move the virtual cursor to the beginning of the line.
- #border ⇒ Vedeu::Borders::Border private
-
#defaults ⇒ Hash<Symbol => Fixnum|NilClass|String|Symbol>
private
Returns the default options/attributes for this class.
-
#down ⇒ Vedeu::Editor::Cursor
Move the virtual cursor down by one line.
-
#initialize(attributes = {}) ⇒ Vedeu::Editor::Cursor
constructor
Returns a new instance of Vedeu::Editor::Cursor.
-
#left ⇒ Vedeu::Editor::Cursor
Move the virtual cursor to the left.
-
#real_x ⇒ Fixnum
private
Return the real x coordinate.
-
#real_y ⇒ Fixnum
private
Return the real y coordinate.
-
#refresh ⇒ Vedeu::Editor::Cursor
Overwrite the cursor of the same name.
-
#reset! ⇒ Vedeu::Editor::Cursor
Move the virtual cursor to the origin (0, 0).
-
#right ⇒ Vedeu::Editor::Cursor
Move the virtual cursor to the right.
-
#to_s ⇒ String
Return the escape sequence as a string for setting the cursor position and show the cursor.
-
#up ⇒ Vedeu::Editor::Cursor
Move the virtual cursor up by one line.
Constructor Details
#initialize(attributes = {}) ⇒ Vedeu::Editor::Cursor
Returns a new instance of Vedeu::Editor::Cursor.
48 49 50 51 52 |
# File 'lib/vedeu/editor/cursor.rb', line 48 def initialize(attributes = {}) defaults.merge!(attributes).each do |key, value| instance_variable_set("@#{key}", value) end end |
Instance Attribute Details
#name ⇒ String|Symbol (readonly)
20 21 22 |
# File 'lib/vedeu/editor/cursor.rb', line 20 def name @name end |
#ox ⇒ Fixnum
24 25 26 |
# File 'lib/vedeu/editor/cursor.rb', line 24 def ox @ox end |
#oy ⇒ Fixnum
28 29 30 |
# File 'lib/vedeu/editor/cursor.rb', line 28 def oy @oy end |
#x ⇒ Fixnum
Returns The column/character coordinate.
32 |
# File 'lib/vedeu/editor/cursor.rb', line 32 attr_writer :x |
#y ⇒ Fixnum
Returns The row/line coordinate.
36 |
# File 'lib/vedeu/editor/cursor.rb', line 36 attr_writer :y |
Instance Method Details
#bol ⇒ Vedeu::Editor::Cursor
Move the virtual cursor to the beginning of the line.
57 58 59 60 61 62 |
# File 'lib/vedeu/editor/cursor.rb', line 57 def bol @ox = 0 @x = 0 self end |
#border ⇒ Vedeu::Borders::Border (private)
160 161 162 |
# File 'lib/vedeu/editor/cursor.rb', line 160 def border @border ||= Vedeu.borders.by_name(name) end |
#defaults ⇒ Hash<Symbol => Fixnum|NilClass|String|Symbol> (private)
Returns the default options/attributes for this class.
167 168 169 170 171 172 173 174 175 |
# File 'lib/vedeu/editor/cursor.rb', line 167 def defaults { name: '', ox: 0, oy: 0, x: 0, y: 0, } end |
#down ⇒ Vedeu::Editor::Cursor
Move the virtual cursor down by one line.
67 68 69 70 71 |
# File 'lib/vedeu/editor/cursor.rb', line 67 def down @y += 1 self end |
#left ⇒ Vedeu::Editor::Cursor
Move the virtual cursor to the left.
76 77 78 79 80 81 |
# File 'lib/vedeu/editor/cursor.rb', line 76 def left @ox -= 1 unless @ox == 0 @x -= 1 self end |
#real_x ⇒ Fixnum (private)
Return the real x coordinate.
187 188 189 |
# File 'lib/vedeu/editor/cursor.rb', line 187 def real_x (bx + x) - ox end |
#real_y ⇒ Fixnum (private)
Return the real y coordinate.
180 181 182 |
# File 'lib/vedeu/editor/cursor.rb', line 180 def real_y (by + y) - oy end |
#refresh ⇒ Vedeu::Editor::Cursor
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.
89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/vedeu/editor/cursor.rb', line 89 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
Move the virtual cursor to the origin (0, 0).
105 106 107 108 109 110 111 112 |
# File 'lib/vedeu/editor/cursor.rb', line 105 def reset! @x = 0 @y = 0 @ox = 0 @oy = 0 self end |
#right ⇒ Vedeu::Editor::Cursor
Move the virtual cursor to the right.
117 118 119 120 121 |
# File 'lib/vedeu/editor/cursor.rb', line 117 def right @x += 1 self end |
#to_s ⇒ String
Return the escape sequence as a string for setting the cursor position and show the cursor.
127 128 129 |
# File 'lib/vedeu/editor/cursor.rb', line 127 def to_s "\e[#{real_y};#{real_x}H\e[?25h".freeze end |
#up ⇒ Vedeu::Editor::Cursor
Move the virtual cursor up by one line.
134 135 136 137 138 139 |
# File 'lib/vedeu/editor/cursor.rb', line 134 def up @oy -= 1 unless @oy == 0 @y -= 1 self end |