From 97a561260aa083c56b76ea005f0edf9a8ec07cd2 Mon Sep 17 00:00:00 2001 From: Bradley Cicenas Date: Mon, 13 Feb 2017 03:37:17 +0000 Subject: [PATCH] add filter string to ctopheader --- grid.go | 5 +++++ widgets/header.go | 19 +++++++++++++++---- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/grid.go b/grid.go index 3f9757d..c77dcb5 100644 --- a/grid.go +++ b/grid.go @@ -77,6 +77,7 @@ func (g *Grid) redrawRows() { // build layout if config.GetToggle("enableHeader") { g.header.SetCount(len(g.containers)) + g.header.SetFilter(config.Get("filterStr")) ui.Body.AddRows(g.header.Row()) } ui.Body.AddRows(fieldHeader()) @@ -161,6 +162,10 @@ func Display(g *Grid) bool { menu = HelpMenu ui.StopLoop() }) + ui.Handle("/sys/kbd/H", func(ui.Event) { + config.Toggle("enableHeader") + g.redrawRows() + }) ui.Handle("/sys/kbd/q", func(ui.Event) { ui.StopLoop() }) diff --git a/widgets/header.go b/widgets/header.go index 8049388..4c4af3c 100644 --- a/widgets/header.go +++ b/widgets/header.go @@ -8,14 +8,16 @@ import ( ) type CTopHeader struct { - Time *ui.Par - Count *ui.Par + Time *ui.Par + Count *ui.Par + Filter *ui.Par } func NewCTopHeader() *CTopHeader { return &CTopHeader{ - Time: headerPar(timeStr()), - Count: headerPar("-"), + Time: headerPar(timeStr()), + Count: headerPar("-"), + Filter: headerPar(""), } } @@ -24,6 +26,7 @@ func (c *CTopHeader) Row() *ui.Row { return ui.NewRow( ui.NewCol(2, 0, c.Time), ui.NewCol(2, 0, c.Count), + ui.NewCol(8, 0, c.Filter), ) } @@ -31,6 +34,14 @@ func (c *CTopHeader) SetCount(val int) { c.Count.Text = fmt.Sprintf("%d containers", val) } +func (c *CTopHeader) SetFilter(val string) { + if val == "" { + c.Filter.Text = "" + } else { + c.Filter.Text = fmt.Sprintf("filter: %s", val) + } +} + func timeStr() string { return time.Now().Local().Format("15:04:05 MST") }