-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
73 lines (59 loc) · 1.25 KB
/
main.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 main
import (
"github.com/Nightgunner5/g/console"
"github.com/Nightgunner5/g/paint"
"github.com/skelterjohn/go.wde"
"image"
"strings"
)
var cleanup []func()
var commands = make(map[string]func([]string))
func main() {
go ui()
wde.Run()
for _, f := range cleanup {
f()
}
}
func ui() {
defer wde.Stop()
w, err := wde.NewWindow(640, 480)
handle(err)
w.SetTitle("g")
w.Show()
paint.Start(func(img *image.RGBA) {
screen := w.Screen()
screen.CopyRGBA(img, screen.Bounds())
w.FlushImage(screen.Bounds())
}, func(argv []string) {
if len(argv) == 0 {
return
}
paint.WithConsole(func(c *console.Console) {
c.Bprint(">")
c.Println(strings.Join(argv, " "))
})
if cmd, ok := commands[argv[0]]; ok {
go cmd(argv[1:])
} else {
paint.WithConsole(func(c *console.Console) {
c.Errorln("Unknown command or filename.")
c.Print("Type")
c.Bprint("help")
c.Println("at the prompt for a listing of basic commands.")
})
}
})
paint.ResetViewport(w.Screen().Bounds())
for event := range w.EventChan() {
switch e := event.(type) {
case wde.CloseEvent:
_ = e
return
case wde.KeyTypedEvent:
paint.Typed(e.Key, e.Glyph)
case wde.ResizeEvent:
paint.ResetViewport(w.Screen().Bounds())
}
}
}