forked from miketheprogrammer/go-thrust
-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo.go
122 lines (100 loc) · 2.95 KB
/
demo.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
package main
import (
"fmt"
"os"
"runtime"
"time"
"github.com/miketheprogrammer/go-thrust/commands"
. "github.com/miketheprogrammer/go-thrust/common"
"github.com/miketheprogrammer/go-thrust/connection"
"github.com/miketheprogrammer/go-thrust/dispatcher"
"github.com/miketheprogrammer/go-thrust/menu"
"github.com/miketheprogrammer/go-thrust/session"
"github.com/miketheprogrammer/go-thrust/spawn"
"github.com/miketheprogrammer/go-thrust/window"
)
func main() {
// Parses Flags
InitLogger()
connection.StdOut, connection.StdIn = spawn.SpawnThrustCore()
err := connection.InitializeThreads()
if err != nil {
fmt.Println(err)
os.Exit(2)
}
out, in := connection.GetCommunicationChannels()
mainSession := session.Session{}
mainSession.Create(in)
thrustWindow := window.Window{
Url: "http://breach.cc/",
}
rootMenu := menu.Menu{}
fileMenu := menu.Menu{}
checkList := menu.Menu{}
radioList := menu.Menu{}
viewMenu := menu.Menu{}
// Calls to other methods after create are Queued until Create returns
thrustWindow.Create(in, nil)
thrustWindow.Show()
rootMenu.Create(in)
rootMenu.AddItem(2, "Root")
fileMenu.Create(in)
fileMenu.AddItem(3, "Open")
fileMenu.RegisterEventHandlerByCommandID(4, func(reply commands.CommandResponse, item *menu.MenuItem) {
os.Exit(2)
})
fileMenu.AddItem(4, "Close")
fileMenu.AddSeparator()
checkList.Create(in)
checkList.AddCheckItem(5, "Check 1")
checkList.SetChecked(5, true)
checkList.AddSeparator()
checkList.AddCheckItem(6, "Check 2")
checkList.SetChecked(6, true)
checkList.SetEnabled(6, false)
radioList.Create(in)
radioList.AddRadioItem(7, "Radio 1-1", 1)
radioList.AddRadioItem(8, "Radio 1-2", 1)
radioList.AddSeparator()
radioList.AddRadioItem(9, "Radio 2-1", 2)
radioList.AddRadioItem(10, "Radio 2-2", 2)
radioList.AddRadioItem(11, "Radio 2-3", 2)
radioList.SetVisible(11, false)
fileMenu.AddSubmenu(11, "CheckList", &checkList)
fileMenu.AddSubmenu(12, "RadioList", &radioList)
viewMenu.Create(in)
layoutMenu := menu.Menu{}
layoutMenu.Create(in)
layoutStyleMenu := menu.Menu{}
layoutStyleMenu.Create(in)
layoutStyleMenu.AddRadioItem(13, "Horizontal", 3)
layoutStyleMenu.AddRadioItem(14, "Vertical", 3)
layoutMenu.AddSubmenu(15, "Styles", &layoutStyleMenu)
viewMenu.AddSubmenu(16, "Layouts", &layoutMenu)
rootMenu.AddSubmenu(17, "File", &fileMenu)
rootMenu.AddSubmenu(18, "View", &viewMenu)
if runtime.GOOS == "darwin" {
rootMenu.SetApplicationMenu()
} else {
rootMenu.AttachToWindow(&thrustWindow)
}
thrustWindow.Maximize()
dispatcher.RegisterHandler(func(c commands.CommandResponse) {
thrustWindow.DispatchResponse(c)
})
dispatcher.RegisterHandler(func(c commands.CommandResponse) {
rootMenu.DispatchResponse(c)
})
dispatcher.RegisterHandler(func(c commands.CommandResponse) {
mainSession.DispatchResponse(c)
})
for {
select {
case response := <-out.CommandResponses:
dispatcher.Dispatch(response)
default:
break
}
time.Sleep(time.Microsecond * 10)
}
}