Class: Vedeu::Editor::Cursor
- Inherits:
-
Object
- Object
- Vedeu::Editor::Cursor
- Defined in:
- lib/vedeu/editor/cursor.rb
Overview
Maintains a cursor position within the Document class.
Instance Attribute Summary collapse
- #bx ⇒ Fixnum
- #bxn ⇒ Fixnum
- #by ⇒ Fixnum
- #byn ⇒ Fixnum
- #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.
-
#defaults ⇒ Hash<Symbol => Fixnum|NilClass>
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.
-
#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 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.
55 56 57 58 59 60 61 |
# File 'lib/vedeu/editor/cursor.rb', line 55 def initialize(attributes = {}) @attributes = defaults.merge!(attributes) @attributes.each do |key, value| instance_variable_set("@#{key}", value) end end |
Instance Attribute Details
#bx ⇒ Fixnum
12 13 14 |
# File 'lib/vedeu/editor/cursor.rb', line 12 def bx @bx end |
#bxn ⇒ Fixnum
20 21 22 |
# File 'lib/vedeu/editor/cursor.rb', line 20 def bxn @bxn end |
#by ⇒ Fixnum
16 17 18 |
# File 'lib/vedeu/editor/cursor.rb', line 16 def by @by end |
#byn ⇒ Fixnum
24 25 26 |
# File 'lib/vedeu/editor/cursor.rb', line 24 def byn @byn end |
#ox ⇒ Fixnum
28 29 30 |
# File 'lib/vedeu/editor/cursor.rb', line 28 def ox @ox end |
#oy ⇒ Fixnum
32 33 34 |
# File 'lib/vedeu/editor/cursor.rb', line 32 def oy @oy end |
#x ⇒ Fixnum
Returns The column/character coordinate.
36 37 38 |
# File 'lib/vedeu/editor/cursor.rb', line 36 def x @x end |
#y ⇒ Fixnum
Returns The row/line coordinate.
40 41 42 |
# File 'lib/vedeu/editor/cursor.rb', line 40 def y @y end |
Instance Method Details
#bol ⇒ Vedeu::Editor::Cursor
Move the virtual cursor to the beginning of the line.
66 67 68 69 70 71 |
# File 'lib/vedeu/editor/cursor.rb', line 66 def bol @ox = 0 @x = 0 self end |
#defaults ⇒ Hash<Symbol => Fixnum|NilClass> (private)
Returns the default options/attributes for this class.
152 153 154 155 156 157 158 159 160 161 162 163 |
# File 'lib/vedeu/editor/cursor.rb', line 152 def defaults { y: 0, x: 0, by: nil, bx: nil, byn: nil, bxn: nil, ox: 0, oy: 0, } end |
#down ⇒ Vedeu::Editor::Cursor
Move the virtual cursor down by one line.
76 77 78 79 80 |
# File 'lib/vedeu/editor/cursor.rb', line 76 def down @y += 1 self end |
#left ⇒ Vedeu::Editor::Cursor
Move the virtual cursor to the left.
85 86 87 88 89 90 |
# File 'lib/vedeu/editor/cursor.rb', line 85 def left @ox -= 1 unless @ox == 0 @x -= 1 self end |
#real_x ⇒ Fixnum (private)
Return the real x coordinate.
175 176 177 |
# File 'lib/vedeu/editor/cursor.rb', line 175 def real_x (bx + x) - ox end |
#real_y ⇒ Fixnum (private)
Return the real y coordinate.
168 169 170 |
# File 'lib/vedeu/editor/cursor.rb', line 168 def real_y (by + y) - oy end |
#reset! ⇒ Vedeu::Editor::Cursor
Move the virtual cursor to the origin (0, 0).
95 96 97 98 99 100 101 102 |
# File 'lib/vedeu/editor/cursor.rb', line 95 def reset! @x = 0 @y = 0 @ox = 0 @oy = 0 self end |
#right ⇒ Vedeu::Editor::Cursor
Move the virtual cursor to the right.
107 108 109 110 111 |
# File 'lib/vedeu/editor/cursor.rb', line 107 def right @x += 1 self end |
#to_s ⇒ String
Return the escape sequence for setting the cursor position and show the cursor.
117 118 119 |
# File 'lib/vedeu/editor/cursor.rb', line 117 def to_s "\e[#{real_y};#{real_x}H\e[?25h" end |
#up ⇒ Vedeu::Editor::Cursor
Move the virtual cursor up by one line.
124 125 126 127 128 129 |
# File 'lib/vedeu/editor/cursor.rb', line 124 def up @oy -= 1 unless @oy == 0 @y -= 1 self end |