align ctop header on resize, add keybinding to help dialog

This commit is contained in:
Bradley Cicenas 2017-02-19 23:52:59 +00:00
parent 335ac8d741
commit 93db38d654
3 changed files with 10 additions and 3 deletions

View File

@ -206,6 +206,7 @@ func Display(g *Grid) bool {
})
ui.Handle("/sys/wnd/resize", func(e ui.Event) {
g.header.Align()
ui.Body.Width = ui.TermWidth()
log.Infof("resize: width=%v max-rows=%v", ui.Body.Width, g.maxRows)
g.redrawRows()

View File

@ -9,6 +9,7 @@ import (
var helpDialog = []menu.Item{
menu.Item{"[h] - open this help dialog", ""},
menu.Item{"[H] - toggle cTop header", ""},
menu.Item{"[s] - select container sort field", ""},
menu.Item{"[r] - reverse container sort order", ""},
menu.Item{"[q] - exit ctop", ""},

View File

@ -17,8 +17,8 @@ type CTopHeader struct {
func NewCTopHeader() *CTopHeader {
return &CTopHeader{
Time: headerPar(2, timeStr()),
Count: headerPar(22, "-"),
Filter: headerPar(42, ""),
Count: headerPar(27, "-"),
Filter: headerPar(47, ""),
bg: headerBg(),
}
}
@ -29,6 +29,10 @@ func (c *CTopHeader) Render() {
ui.Render(c.Time, c.Count, c.Filter)
}
func (c *CTopHeader) Align() {
c.bg.SetWidth(ui.TermWidth() - 1)
}
func (c *CTopHeader) Height() int {
return c.bg.Height
}
@ -65,7 +69,8 @@ func (c *CTopHeader) SetFilter(val string) {
}
func timeStr() string {
return time.Now().Local().Format("15:04:05 MST")
ts := time.Now().Local().Format("15:04:05 MST")
return fmt.Sprintf("cTop - %s", ts)
}
func headerPar(x int, s string) *ui.Par {