-
Notifications
You must be signed in to change notification settings - Fork 0
/
input.go
73 lines (68 loc) · 1.05 KB
/
input.go
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package tui
const (
KeyEsc = "\x1b"
KeyUp = "\x1b[A"
KeyDown = "\x1b[B"
KeyLeft = "\x1b[D"
KeyRight = "\x1b[C"
KeyDelete = "\x1b[3~"
KeyBackspace = "\u007f"
CtrlA = "\x01"
CtrlB = "\x02"
CtrlC = "\x03"
Enter = "\r"
)
type Inputable interface {
InputHandler(string)
}
const (
WasdCursor = iota
ArrowCursor
ViCursor
)
func InputMoveCursor(mode int, input string, cursor *Cursor) bool {
switch mode {
case WasdCursor:
switch input {
case "w":
cursor.Up()
case "a":
cursor.Left()
case "s":
cursor.Down()
case "d":
cursor.Right()
default:
return false
}
case ArrowCursor:
switch input {
case KeyUp:
cursor.Up()
case KeyLeft:
cursor.Left()
case KeyDown:
cursor.Down()
case KeyRight:
cursor.Right()
default:
return false
}
case ViCursor:
switch input {
case "h":
cursor.Left()
case "j":
cursor.Down()
case "k":
cursor.Up()
case "l":
cursor.Right()
default:
return false
}
default:
return false
}
return true
}