summaryrefslogtreecommitdiff
path: root/toolkit/gocui/main.go
blob: ed9670aa318475d687d24f868ee9d6449c061ed4 (plain)
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
// Copyright 2014 The gocui Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package main

import (
	"os"
	"git.wit.org/wit/gui/toolkit"
)

func Init() {
	log(logInfo, "Init() of awesome-gocui")
	me.defaultWidth = 10
	me.defaultHeight = 2 // this means by default one line of text in a button
	me.defaultBehavior = true

	me.horizontalPadding = 20
	me.horizontalPadding = 20
	me.groupPadding = 4
	me.buttonPadding = 3

	// the raw beginning of each window (or tab)
	me.rawW = 7
	me.rawH = 3

	me.padW = 3
	me.padH = 3

	me.pluginChan = make(chan toolkit.Action)

	log(logNow, "Init() start pluginChan")
	go catchActionChannel()
}

// this sets the channel to send user events back from the plugin
func Callback(guiCallback chan toolkit.Action) {
	me.callback = guiCallback
}

func PluginChannel() chan toolkit.Action {
	return me.pluginChan
}

func catchActionChannel() {
	log(logNow, "makeCallback() START")
	for {
		log(logNow, "makeCallback() for loop")
	    	select {
		case a := <-me.pluginChan:
			log(logNow, "makeCallback() SELECT widget id =", a.WidgetId, a.Name)
			action(&a)
			sleep(.1)
		}
	}
}

func Exit() {
	// TODO: send exit to the plugin
	me.baseGui.Close()
}

func Main(f func()) {
	log("start Init()")

	outf, err := os.OpenFile("/tmp/witgui.log", os.O_RDWR | os.O_CREATE | os.O_APPEND, 0666)
	if err != nil {
		exit("error opening file: %v", err)
	}
	defer outf.Close()

	setOutput(outf)
	log("This is a test log entry")

	MouseMain()
	me.baseGui.Close()
}