2024-01-01 16:11:54 -06:00
|
|
|
// 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"
|
2024-01-08 20:52:10 -06:00
|
|
|
|
|
|
|
"go.wit.com/log"
|
2024-01-05 13:35:01 -06:00
|
|
|
"go.wit.com/gui/widget"
|
2024-01-01 16:11:54 -06:00
|
|
|
)
|
|
|
|
|
|
|
|
// sets defaults and establishes communication
|
|
|
|
// to this toolkit from the wit/gui golang package
|
|
|
|
func init() {
|
2024-01-08 20:52:10 -06:00
|
|
|
log.Log(INFO, "Init() of awesome-gocui")
|
2024-01-01 16:11:54 -06:00
|
|
|
|
|
|
|
// init the config struct default values
|
|
|
|
Set(&me, "default")
|
|
|
|
|
2024-01-05 13:35:01 -06:00
|
|
|
pluginChan = make(chan widget.Action)
|
2024-01-01 16:11:54 -06:00
|
|
|
|
2024-01-08 20:52:10 -06:00
|
|
|
log.Log(NOW, "Init() start pluginChan")
|
2024-01-01 16:11:54 -06:00
|
|
|
go catchActionChannel()
|
2024-01-08 20:52:10 -06:00
|
|
|
log.Sleep(.1) // probably not needed, but in here for now under development
|
2024-01-01 16:11:54 -06:00
|
|
|
go main()
|
2024-01-08 20:52:10 -06:00
|
|
|
log.Sleep(.1) // probably not needed, but in here for now under development
|
2024-01-01 16:11:54 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
recieves requests from the program to do things like:
|
|
|
|
* add new widgets
|
|
|
|
* change the text of a label
|
|
|
|
* etc..
|
|
|
|
*/
|
|
|
|
func catchActionChannel() {
|
2024-01-08 20:52:10 -06:00
|
|
|
log.Log(INFO, "catchActionChannel() START")
|
2024-01-01 16:11:54 -06:00
|
|
|
for {
|
2024-01-08 20:52:10 -06:00
|
|
|
log.Log(INFO, "catchActionChannel() infinite for() loop restarted select on channel")
|
2024-01-01 16:11:54 -06:00
|
|
|
select {
|
|
|
|
case a := <-pluginChan:
|
|
|
|
if (me.baseGui == nil) {
|
|
|
|
// something went wrong initializing the gocui
|
2024-01-08 20:52:10 -06:00
|
|
|
log.Log(ERROR, "ERROR: console did not initialize")
|
2024-01-01 16:11:54 -06:00
|
|
|
continue
|
|
|
|
}
|
2024-01-11 19:10:24 -06:00
|
|
|
log.Log(INFO, "catchActionChannel()", a.WidgetId, a.ActionType, a.WidgetType, a.ProgName)
|
2024-01-01 16:11:54 -06:00
|
|
|
action(&a)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func Exit() {
|
|
|
|
// TODO: what should actually happen here?
|
2024-01-08 20:52:10 -06:00
|
|
|
log.Log(NOW, "Exit() here. doing standardExit()")
|
2024-01-01 16:11:54 -06:00
|
|
|
standardExit()
|
|
|
|
}
|
|
|
|
|
|
|
|
func standardExit() {
|
2024-01-08 20:52:10 -06:00
|
|
|
log.Log(NOW, "standardExit() doing baseGui.Close()")
|
2024-01-01 16:11:54 -06:00
|
|
|
me.baseGui.Close()
|
2024-01-08 20:52:10 -06:00
|
|
|
log.Log(NOW, "standardExit() doing outf.Close()")
|
2024-01-01 16:11:54 -06:00
|
|
|
outf.Close()
|
|
|
|
// log(true, "standardExit() setOutput(os.Stdout)")
|
|
|
|
// setOutput(os.Stdout)
|
2024-01-08 20:52:10 -06:00
|
|
|
log.Log(NOW, "standardExit() send back Quit()")
|
2024-01-01 16:11:54 -06:00
|
|
|
go sendBackQuit() // don't stall here in case the
|
|
|
|
// induces a delay in case the callback channel is broken
|
2024-01-08 20:52:10 -06:00
|
|
|
log.Sleep(1)
|
|
|
|
log.Log(NOW, "standardExit() exit()")
|
|
|
|
os.Exit(0)
|
2024-01-01 16:11:54 -06:00
|
|
|
}
|
|
|
|
func sendBackQuit() {
|
|
|
|
// send 'Quit' back to the program (?)
|
2024-01-05 13:35:01 -06:00
|
|
|
var a widget.Action
|
|
|
|
a.ActionType = widget.UserQuit
|
2024-01-01 16:11:54 -06:00
|
|
|
callback <- a
|
|
|
|
}
|
|
|
|
|
|
|
|
var outf *os.File
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
var err error
|
2024-01-08 20:52:10 -06:00
|
|
|
log.Log(INFO, "main() start Init()")
|
2024-01-01 16:11:54 -06:00
|
|
|
|
|
|
|
outf, err = os.OpenFile("/tmp/witgui.log", os.O_RDWR | os.O_CREATE | os.O_APPEND, 0666)
|
|
|
|
if err != nil {
|
2024-01-08 20:52:10 -06:00
|
|
|
log.Error(err, "error opening file: %v")
|
|
|
|
os.Exit(0)
|
2024-01-01 16:11:54 -06:00
|
|
|
}
|
|
|
|
os.Stdout = outf
|
|
|
|
defer outf.Close()
|
|
|
|
|
|
|
|
// setOutput(outf)
|
|
|
|
// log("This is a test log entry")
|
|
|
|
|
|
|
|
ferr, _ := os.OpenFile("/tmp/witgui.err", os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0664)
|
|
|
|
os.Stderr = ferr
|
|
|
|
gocuiMain()
|
|
|
|
|
2024-01-08 20:52:10 -06:00
|
|
|
log.Log(NOW, "MouseMain() closed")
|
2024-01-01 16:11:54 -06:00
|
|
|
standardExit()
|
|
|
|
}
|