-
Notifications
You must be signed in to change notification settings - Fork 46
/
input.go
78 lines (71 loc) · 1.57 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
74
75
76
77
78
package main
import (
"fmt"
"github.com/aaronjanse/3mux/ecma48"
"github.com/aaronjanse/3mux/wm"
)
var mouseDownX, mouseDownY int
// seiveMouseEvents processes mouse events and returns true if the data should *not* be passed downstream
func seiveMouseEvents(u *wm.Universe, human string, obj ecma48.Output) bool {
switch ev := obj.Parsed.(type) {
case ecma48.MouseDown:
u.SelectAtCoords(ev.X, ev.Y)
mouseDownX = ev.X
mouseDownY = ev.Y
case ecma48.MouseUp:
u.DragBorder(mouseDownX, mouseDownY, ev.X, ev.Y)
case ecma48.MouseDrag:
// do nothing
case ecma48.ScrollUp:
u.ScrollUp()
case ecma48.ScrollDown:
u.ScrollDown()
default:
return false
}
return true
}
func humanify(obj ecma48.Output) string {
humanCode := ""
switch x := obj.Parsed.(type) {
case ecma48.Char:
humanCode = string(x.Rune)
case ecma48.CtrlChar:
humanCode = fmt.Sprintf("Ctrl+%s", humanifyRune(x.Char))
case ecma48.AltChar:
humanCode = fmt.Sprintf("Alt+%s", humanifyRune(x.Char))
case ecma48.AltShiftChar:
humanCode = fmt.Sprintf("Alt+Shift+%s", humanifyRune(x.Char))
case ecma48.Tab:
humanCode = "Tab"
case ecma48.CursorMovement:
if x.Ctrl {
humanCode += "Ctrl+"
}
if x.Alt {
humanCode += "Alt+"
}
if x.Shift {
humanCode += "Shift+"
}
switch x.Direction {
case ecma48.Up:
humanCode += "Up"
case ecma48.Down:
humanCode += "Down"
case ecma48.Left:
humanCode += "Left"
case ecma48.Right:
humanCode += "Right"
}
}
return humanCode
}
func humanifyRune(r rune) string {
switch r {
case '\n', '\r':
return "Enter"
default:
return string(r)
}
}