Class: Vedeu::Cursor
- Inherits:
-
Object
show all
- Extended by:
- Forwardable
- Includes:
- Model
- Defined in:
- lib/vedeu/cursor/cursor.rb
Overview
Each interface has its own Cursor which maintains the position and visibility of the cursor within that interface.
Instance Attribute Summary collapse
Attributes included from Model
#repository
Instance Method Summary
collapse
Methods included from Model
#demodulize, #deputy, #dsl_class, included, #store
Constructor Details
#initialize(attributes = {}) ⇒ Cursor
Returns a new instance of Vedeu::Cursor.
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
# File 'lib/vedeu/cursor/cursor.rb', line 58
def initialize(attributes = {})
attributes = { name: attributes } if attributes.is_a?(String)
@attributes = defaults.merge!(attributes)
@name = @attributes.fetch(:name)
@ox = @attributes.fetch(:ox)
@oy = @attributes.fetch(:oy)
@repository = @attributes.fetch(:repository)
@visible = @attributes.fetch(:visible)
@x = @attributes.fetch(:x)
@y = @attributes.fetch(:y)
@position = Vedeu::Position.new(@y, @x)
end
|
Instance Attribute Details
#attributes ⇒ Hash
14
15
16
|
# File 'lib/vedeu/cursor/cursor.rb', line 14
def attributes
@attributes
end
|
#name ⇒ String
18
19
20
|
# File 'lib/vedeu/cursor/cursor.rb', line 18
def name
@name
end
|
#ox ⇒ Fixnum
22
23
24
|
# File 'lib/vedeu/cursor/cursor.rb', line 22
def ox
@ox
end
|
#oy ⇒ Fixnum
26
27
28
|
# File 'lib/vedeu/cursor/cursor.rb', line 26
def oy
@oy
end
|
#state ⇒ Boolean|Symbol
30
31
32
|
# File 'lib/vedeu/cursor/cursor.rb', line 30
def state
@state
end
|
#visible ⇒ Boolean|Symbol
Also known as:
visible?
34
35
36
|
# File 'lib/vedeu/cursor/cursor.rb', line 34
def visible
@visible
end
|
#x ⇒ Fixnum
39
40
41
|
# File 'lib/vedeu/cursor/cursor.rb', line 39
def x
@x
end
|
#y ⇒ Fixnum
43
44
45
|
# File 'lib/vedeu/cursor/cursor.rb', line 43
def y
@y
end
|
Instance Method Details
#defaults ⇒ Hash
The default values for a new instance of this class.
113
114
115
116
117
118
119
120
121
122
123
|
# File 'lib/vedeu/cursor/cursor.rb', line 113
def defaults
{
name: '',
ox: 0,
oy: 0,
repository: Vedeu.cursors,
visible: false,
x: 1,
y: 1,
}
end
|
#inspect ⇒ String
77
78
79
80
81
82
83
84
|
# File 'lib/vedeu/cursor/cursor.rb', line 77
def inspect
"<Vedeu::Cursor (#{name}, " \
"#{visible}, " \
"x:#{x}, " \
"y:#{y}, " \
"ox:#{ox}, " \
"oy:#{oy})>"
end
|
Return the position of this cursor.
106
107
108
|
# File 'lib/vedeu/cursor/cursor.rb', line 106
def position
@position ||= Vedeu::Position.new(y, x)
end
|
#sequence ⇒ String
Returns the escape sequence to position the cursor and set its visibility.
128
129
130
|
# File 'lib/vedeu/cursor/cursor.rb', line 128
def sequence
[position, visibility].join
end
|
#to_s ⇒ String
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.
91
92
93
94
95
96
97
98
99
|
# File 'lib/vedeu/cursor/cursor.rb', line 91
def to_s
if block_given?
[sequence, yield, sequence].join
else
sequence
end
end
|
#visibility ⇒ String
Returns the escape sequence for setting the visibility of the cursor.
135
136
137
138
139
140
141
142
143
|
# File 'lib/vedeu/cursor/cursor.rb', line 135
def visibility
if visible?
show_cursor
else
hide_cursor
end
end
|