From 4fbc998a41de6a4021a61a996b29ec2e49686d4e Mon Sep 17 00:00:00 2001 From: Sergey Ponomarev Date: Mon, 23 Nov 2020 14:27:47 +0200 Subject: [PATCH 1/3] status.go: simplify Buffer() s.health and s.status are always have only one element with a single char length --- cwidgets/compact/status.go | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/cwidgets/compact/status.go b/cwidgets/compact/status.go index b5bb261..783cd0e 100644 --- a/cwidgets/compact/status.go +++ b/cwidgets/compact/status.go @@ -32,16 +32,8 @@ func NewStatus() CompactCol { func (s *Status) Buffer() ui.Buffer { buf := s.Block.Buffer() - x := 0 - for _, c := range s.health { - buf.Set(s.InnerX()+x, s.InnerY(), c) - x += c.Width() - } - x += 1 - for _, c := range s.status { - buf.Set(s.InnerX()+x, s.InnerY(), c) - x += c.Width() - } + buf.Set(s.InnerX(), s.InnerY(), s.health[0]) + buf.Set(s.InnerX()+2, s.InnerY(), s.status[0]) return buf } From 10c49018a6f4402befd6a2836adebb4e4fad837f Mon Sep 17 00:00:00 2001 From: Sergey Ponomarev Date: Wed, 25 Nov 2020 22:21:19 +0200 Subject: [PATCH 2/3] status.go: make logic more explicit --- cwidgets/compact/status.go | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/cwidgets/compact/status.go b/cwidgets/compact/status.go index 783cd0e..bb70cca 100644 --- a/cwidgets/compact/status.go +++ b/cwidgets/compact/status.go @@ -22,11 +22,11 @@ type Status struct { func NewStatus() CompactCol { s := &Status{ Block: ui.NewBlock(), + status: []ui.Cell{{Ch: ' '}}, health: []ui.Cell{{Ch: ' '}}, } s.Height = 1 s.Border = false - s.setState("") return s } @@ -51,17 +51,25 @@ func (s *Status) Header() string { return "" } func (s *Status) FixedWidth() int { return 3 } func (s *Status) setState(val string) { - // defaults - text := mark color := ui.ColorDefault + var text string switch val { + case "": + return + case "created": + text = mark case "running": + text = mark color = ui.ThemeAttr("status.ok") case "exited": + text = mark color = ui.ThemeAttr("status.danger") case "paused": text = vBar + default: + text = " " + log.Warningf("unknown status string: \"%v\"", val) } s.status = ui.TextCells(text, color, ui.ColorDefault) @@ -69,18 +77,22 @@ func (s *Status) setState(val string) { func (s *Status) setHealth(val string) { color := ui.ColorDefault - mark := healthMark + var mark string switch val { case "": return case "healthy": + mark = healthMark color = ui.ThemeAttr("status.ok") case "unhealthy": + mark = healthMark color = ui.ThemeAttr("status.danger") case "starting": + mark = healthMark color = ui.ThemeAttr("status.warn") default: + mark = " " log.Warningf("unknown health state string: \"%v\"", val) } From 4850f817f3e5a74224456aef2374c526bb0003b3 Mon Sep 17 00:00:00 2001 From: Sergey Ponomarev Date: Wed, 25 Nov 2020 22:29:10 +0200 Subject: [PATCH 3/3] status.go: use more clear status marks --- cwidgets/compact/status.go | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/cwidgets/compact/status.go b/cwidgets/compact/status.go index bb70cca..3265ca4 100644 --- a/cwidgets/compact/status.go +++ b/cwidgets/compact/status.go @@ -6,12 +6,6 @@ import ( ui "github.com/gizak/termui" ) -const ( - mark = "◉" - healthMark = "✚" - vBar = string('\u25AE') + string('\u25AE') -) - // Status indicator type Status struct { *ui.Block @@ -52,27 +46,27 @@ func (s *Status) FixedWidth() int { return 3 } func (s *Status) setState(val string) { color := ui.ColorDefault - var text string + var mark string switch val { case "": return case "created": - text = mark + mark = "◉" case "running": - text = mark + mark = "⏵" color = ui.ThemeAttr("status.ok") case "exited": - text = mark + mark = "⏹" color = ui.ThemeAttr("status.danger") case "paused": - text = vBar + mark = "⏸" default: - text = " " + mark = " " log.Warningf("unknown status string: \"%v\"", val) } - s.status = ui.TextCells(text, color, ui.ColorDefault) + s.status = ui.TextCells(mark, color, ui.ColorDefault) } func (s *Status) setHealth(val string) { @@ -83,13 +77,13 @@ func (s *Status) setHealth(val string) { case "": return case "healthy": - mark = healthMark + mark = "☼" color = ui.ThemeAttr("status.ok") case "unhealthy": - mark = healthMark + mark = "⚠" color = ui.ThemeAttr("status.danger") case "starting": - mark = healthMark + mark = "◌" color = ui.ThemeAttr("status.warn") default: mark = " "