defer waiting for the process to close instead direct

This commit is contained in:
Krumel
2021-06-04 19:11:26 +02:00
parent adee80567d
commit 70ce93ae54

View File

@ -101,7 +101,6 @@ func server_run(g *gocui.Gui) {
if buf.Scan() { if buf.Scan() {
g.Update(func(g *gocui.Gui) error { g.Update(func(g *gocui.Gui) error {
v, err := g.View("srv_log") v, err := g.View("srv_log")
g.SetCurrentView("srv_log")
if err != nil { if err != nil {
return err return err
} }
@ -125,7 +124,6 @@ func server_run(g *gocui.Gui) {
fmt.Fprintln(v, buf.Text()) fmt.Fprintln(v, buf.Text())
} }
g.SetCurrentView("input")
return nil return nil
}) })
} else { } else {
@ -139,32 +137,32 @@ func main() {
reload() reload()
//init the CUI //init the CUI
g, err := gocui.NewGui(gocui.OutputNormal, true) gui, err := gocui.NewGui(gocui.OutputNormal, true)
if err != nil { if err != nil {
log.Panicln(err) log.Panicln(err)
} }
defer g.Close() defer gui.Close()
g.SetManagerFunc(layout) gui.SetManagerFunc(layout)
g.Cursor = false gui.Cursor = false
if err := g.SetKeybinding("", gocui.KeyCtrlC, gocui.ModNone, quit); err != nil { if err := gui.SetKeybinding("", gocui.KeyCtrlC, gocui.ModNone, quit); err != nil {
log.Panicln(err) log.Panicln(err)
} }
if err := g.SetKeybinding("", gocui.KeyCtrlI, gocui.ModNone, procstatus); err != nil { if err := gui.SetKeybinding("", gocui.KeyCtrlI, gocui.ModNone, procstatus); err != nil {
log.Panicln(err) log.Panicln(err)
} }
if err := g.SetKeybinding("", gocui.KeyCtrlD, gocui.ModNone, killserver); err != nil { if err := gui.SetKeybinding("", gocui.KeyCtrlD, gocui.ModNone, killserver); err != nil {
log.Panicln(err) log.Panicln(err)
} }
go server_run(g) go server_run(gui)
//run the CUI main loop //run the CUI main loop
if err := g.MainLoop(); err != nil && err != gocui.ErrQuit { if err := gui.MainLoop(); err != nil && err != gocui.ErrQuit {
log.Panicln(err) log.Panicln(err)
} }
} }
@ -278,7 +276,7 @@ func quit(g *gocui.Gui, v *gocui.View) error {
v_status.Clear() v_status.Clear()
fmt.Fprintf(v_status, "Server process still running, sending SIGINT... ") fmt.Fprintf(v_status, "Server process still running, sending SIGINT... ")
srv_cmd.Process.Signal(syscall.SIGINT) srv_cmd.Process.Signal(syscall.SIGINT)
err = srv_cmd.Wait() defer srv_cmd.Wait()
if err != nil { if err != nil {
fmt.Fprintf(v_status, fmt.Sprint(err)) fmt.Fprintf(v_status, fmt.Sprint(err))
} }