2016-12-22 16:15:22 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2017-02-07 03:33:09 +00:00
|
|
|
"github.com/bcicen/ctop/config"
|
2017-03-06 08:51:50 +00:00
|
|
|
"github.com/bcicen/ctop/cwidgets/expanded"
|
2016-12-22 16:15:22 +00:00
|
|
|
ui "github.com/gizak/termui"
|
|
|
|
)
|
|
|
|
|
2017-03-08 00:10:38 +00:00
|
|
|
func RedrawRows(clr bool) {
|
2016-12-30 22:10:49 +00:00
|
|
|
// reinit body rows
|
2017-02-26 22:04:24 +00:00
|
|
|
cGrid.Clear()
|
2017-01-02 20:14:35 +00:00
|
|
|
|
2016-12-30 22:10:49 +00:00
|
|
|
// build layout
|
2017-02-26 06:22:50 +00:00
|
|
|
y := 1
|
2017-02-16 04:06:05 +00:00
|
|
|
if config.GetSwitchVal("enableHeader") {
|
2017-03-06 03:03:05 +00:00
|
|
|
header.SetCount(cursor.Len())
|
2017-03-06 02:00:30 +00:00
|
|
|
header.SetFilter(config.GetVal("filterStr"))
|
|
|
|
y += header.Height()
|
2017-01-06 13:49:22 +00:00
|
|
|
}
|
2017-02-26 07:31:23 +00:00
|
|
|
cGrid.SetY(y)
|
2017-02-24 09:10:14 +00:00
|
|
|
|
2017-03-08 07:45:31 +00:00
|
|
|
for _, c := range cursor.filtered {
|
2017-03-03 07:57:26 +00:00
|
|
|
cGrid.AddRows(c.Widgets)
|
2017-02-24 09:10:14 +00:00
|
|
|
}
|
|
|
|
|
2017-03-08 00:10:38 +00:00
|
|
|
if clr {
|
|
|
|
ui.Clear()
|
|
|
|
log.Debugf("screen cleared")
|
|
|
|
}
|
2017-02-26 07:31:23 +00:00
|
|
|
if config.GetSwitchVal("enableHeader") {
|
2017-03-09 08:33:25 +00:00
|
|
|
ui.Render(header)
|
2017-02-26 07:31:23 +00:00
|
|
|
}
|
|
|
|
cGrid.Align()
|
2017-02-26 06:22:50 +00:00
|
|
|
ui.Render(cGrid)
|
2016-12-22 16:15:22 +00:00
|
|
|
}
|
|
|
|
|
2017-03-06 08:51:50 +00:00
|
|
|
func ExpandView(c *Container) {
|
|
|
|
ui.Clear()
|
|
|
|
ui.DefaultEvtStream.ResetHandlers()
|
|
|
|
defer ui.DefaultEvtStream.ResetHandlers()
|
|
|
|
|
2017-03-06 22:05:04 +00:00
|
|
|
ex := expanded.NewExpanded(c.Id)
|
|
|
|
c.SetUpdater(ex)
|
2017-03-06 08:51:50 +00:00
|
|
|
|
2017-03-06 22:05:04 +00:00
|
|
|
ex.Align()
|
|
|
|
ui.Render(ex)
|
2017-03-06 08:51:50 +00:00
|
|
|
ui.Handle("/timer/1s", func(ui.Event) {
|
2017-03-06 22:05:04 +00:00
|
|
|
ui.Render(ex)
|
|
|
|
})
|
|
|
|
ui.Handle("/sys/wnd/resize", func(e ui.Event) {
|
|
|
|
ex.SetWidth(ui.TermWidth())
|
|
|
|
ex.Align()
|
2017-03-08 00:52:31 +00:00
|
|
|
log.Infof("resize: width=%v max-rows=%v", ex.Width, cGrid.MaxRows())
|
2017-03-06 08:51:50 +00:00
|
|
|
})
|
|
|
|
ui.Handle("/sys/kbd/", func(ui.Event) {
|
|
|
|
ui.StopLoop()
|
|
|
|
})
|
|
|
|
ui.Loop()
|
|
|
|
|
|
|
|
c.SetUpdater(c.Widgets)
|
|
|
|
}
|
2017-01-06 19:46:30 +00:00
|
|
|
|
2017-03-08 00:10:38 +00:00
|
|
|
func RefreshDisplay() {
|
|
|
|
needsClear := cursor.RefreshContainers()
|
|
|
|
RedrawRows(needsClear)
|
|
|
|
}
|
|
|
|
|
2017-03-06 03:03:05 +00:00
|
|
|
func Display() bool {
|
2017-01-08 23:07:58 +00:00
|
|
|
var menu func()
|
2017-03-06 08:51:50 +00:00
|
|
|
var expand bool
|
2017-01-01 22:42:13 +00:00
|
|
|
|
2017-02-26 06:22:50 +00:00
|
|
|
cGrid.SetWidth(ui.TermWidth())
|
2017-02-05 00:56:45 +00:00
|
|
|
ui.DefaultEvtStream.Hook(logEvent)
|
|
|
|
|
2017-02-18 03:31:50 +00:00
|
|
|
// initial draw
|
2017-03-06 02:00:30 +00:00
|
|
|
header.Align()
|
2017-03-06 03:03:05 +00:00
|
|
|
cursor.RefreshContainers()
|
2017-03-08 00:10:38 +00:00
|
|
|
RedrawRows(true)
|
2016-12-22 16:15:22 +00:00
|
|
|
|
2017-03-09 05:29:34 +00:00
|
|
|
ui.Handle("/sys/kbd/<up>", func(ui.Event) { cursor.Up() })
|
|
|
|
ui.Handle("/sys/kbd/<down>", func(ui.Event) { cursor.Down() })
|
2017-01-06 19:46:30 +00:00
|
|
|
ui.Handle("/sys/kbd/<enter>", func(ui.Event) {
|
2017-03-06 08:51:50 +00:00
|
|
|
expand = true
|
|
|
|
ui.StopLoop()
|
2017-01-06 19:46:30 +00:00
|
|
|
})
|
2017-02-23 22:00:05 +00:00
|
|
|
|
2017-03-09 05:29:34 +00:00
|
|
|
ui.Handle("/sys/kbd/q", func(ui.Event) { ui.StopLoop() })
|
|
|
|
ui.Handle("/sys/kbd/C-c", func(ui.Event) { ui.StopLoop() })
|
|
|
|
|
2017-02-16 00:00:31 +00:00
|
|
|
ui.Handle("/sys/kbd/a", func(ui.Event) {
|
|
|
|
config.Toggle("allContainers")
|
2017-03-08 00:10:38 +00:00
|
|
|
RefreshDisplay()
|
2017-02-16 00:00:31 +00:00
|
|
|
})
|
2017-03-01 01:10:33 +00:00
|
|
|
ui.Handle("/sys/kbd/D", func(ui.Event) {
|
2017-03-06 03:03:05 +00:00
|
|
|
dumpContainer(cursor.Selected())
|
2017-03-01 01:10:33 +00:00
|
|
|
})
|
2017-01-21 18:15:29 +00:00
|
|
|
ui.Handle("/sys/kbd/f", func(ui.Event) {
|
|
|
|
menu = FilterMenu
|
|
|
|
ui.StopLoop()
|
|
|
|
})
|
2017-01-01 22:42:13 +00:00
|
|
|
ui.Handle("/sys/kbd/h", func(ui.Event) {
|
2017-01-08 23:07:58 +00:00
|
|
|
menu = HelpMenu
|
2017-01-02 23:40:55 +00:00
|
|
|
ui.StopLoop()
|
|
|
|
})
|
2017-02-13 03:37:17 +00:00
|
|
|
ui.Handle("/sys/kbd/H", func(ui.Event) {
|
|
|
|
config.Toggle("enableHeader")
|
2017-03-08 00:10:38 +00:00
|
|
|
RedrawRows(true)
|
2017-02-13 03:37:17 +00:00
|
|
|
})
|
2017-01-21 18:15:29 +00:00
|
|
|
ui.Handle("/sys/kbd/r", func(e ui.Event) {
|
2017-02-07 03:33:09 +00:00
|
|
|
config.Toggle("sortReversed")
|
2017-01-12 19:48:29 +00:00
|
|
|
})
|
|
|
|
ui.Handle("/sys/kbd/s", func(ui.Event) {
|
|
|
|
menu = SortMenu
|
2016-12-22 16:15:22 +00:00
|
|
|
ui.StopLoop()
|
|
|
|
})
|
2017-02-23 22:00:05 +00:00
|
|
|
|
2016-12-22 16:15:22 +00:00
|
|
|
ui.Handle("/timer/1s", func(e ui.Event) {
|
2017-03-08 00:10:38 +00:00
|
|
|
RefreshDisplay()
|
2016-12-22 16:15:22 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
ui.Handle("/sys/wnd/resize", func(e ui.Event) {
|
2017-03-06 02:00:30 +00:00
|
|
|
header.Align()
|
2017-03-08 07:45:31 +00:00
|
|
|
cursor.ScrollPage()
|
2017-02-26 06:22:50 +00:00
|
|
|
cGrid.SetWidth(ui.TermWidth())
|
2017-03-08 00:52:31 +00:00
|
|
|
log.Infof("resize: width=%v max-rows=%v", cGrid.Width, cGrid.MaxRows())
|
2017-03-08 00:10:38 +00:00
|
|
|
RedrawRows(true)
|
2016-12-22 16:15:22 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
ui.Loop()
|
2017-01-08 23:07:58 +00:00
|
|
|
if menu != nil {
|
2017-02-13 03:22:32 +00:00
|
|
|
menu()
|
2017-01-01 22:42:13 +00:00
|
|
|
return false
|
|
|
|
}
|
2017-03-06 08:51:50 +00:00
|
|
|
if expand {
|
|
|
|
ExpandView(cursor.Selected())
|
|
|
|
return false
|
|
|
|
}
|
2017-01-01 22:42:13 +00:00
|
|
|
return true
|
2016-12-22 16:15:22 +00:00
|
|
|
}
|