-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcursor.rb
More file actions
55 lines (43 loc) · 687 Bytes
/
cursor.rb
File metadata and controls
55 lines (43 loc) · 687 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#basic cursor implementation
class Cursor
attr_reader :row, :col, :width, :height
def initialize(width = 8, height = 8)
@width = width
@height = height
@row = 0
@col = 0
end
def pos
[self.row, self.col]
end
def pos=(new_pos)
@row = new_pos[0]
@col = new_pos[1]
end
def left
@col = (col - 1) % self.width
end
def right
@col = (col + 1) % self.width
end
def up
@row = (row - 1) % self.height
end
def down
@row = (row + 1) % self.height
end
def scroll(sym)
case sym
when :w
up
when :a
left
when :s
down
when :d
right
when :q
exit
end
end
end