From 93db38d654fd7eb0f453fee71486d2b9d6937873 Mon Sep 17 00:00:00 2001 From: Bradley Cicenas Date: Sun, 19 Feb 2017 23:52:59 +0000 Subject: [PATCH] align ctop header on resize, add keybinding to help dialog --- grid.go | 1 + menus.go | 1 + widgets/header.go | 11 ++++++++--- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/grid.go b/grid.go index 2d1b756..3021060 100644 --- a/grid.go +++ b/grid.go @@ -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() diff --git a/menus.go b/menus.go index 2520fcc..64680b4 100644 --- a/menus.go +++ b/menus.go @@ -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", ""}, diff --git a/widgets/header.go b/widgets/header.go index 3df8098..beec1e6 100644 --- a/widgets/header.go +++ b/widgets/header.go @@ -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 {