prevent panic messages from being hidden due to ui.Init() race condition

This commit is contained in:
Bradley Cicenas 2017-06-08 17:19:34 -03:00
parent b009a260a4
commit 6392d63ff8

17
main.go
View File

@ -11,6 +11,7 @@ import (
"github.com/bcicen/ctop/logging" "github.com/bcicen/ctop/logging"
"github.com/bcicen/ctop/widgets" "github.com/bcicen/ctop/widgets"
ui "github.com/gizak/termui" ui "github.com/gizak/termui"
tm "github.com/nsf/termbox-go"
) )
var ( var (
@ -72,6 +73,12 @@ func main() {
config.Toggle("sortReversed") config.Toggle("sortReversed")
} }
defer Shutdown()
// init grid, cursor, header
cursor = NewGridCursor()
cGrid = compact.NewCompactGrid()
header = widgets.NewCTopHeader()
// init ui // init ui
if *invertFlag { if *invertFlag {
InvertColorMap() InvertColorMap()
@ -81,12 +88,6 @@ func main() {
panic(err) panic(err)
} }
defer Shutdown()
// init grid, cursor, header
cursor = NewGridCursor()
cGrid = compact.NewCompactGrid()
header = widgets.NewCTopHeader()
for { for {
exit := Display() exit := Display()
if exit { if exit {
@ -98,7 +99,9 @@ func main() {
func Shutdown() { func Shutdown() {
log.Notice("shutting down") log.Notice("shutting down")
log.Exit() log.Exit()
ui.Close() if tm.IsInit {
ui.Close()
}
} }
// ensure a given sort field is valid // ensure a given sort field is valid