Merge pull request #236 from stokito/status_unicode

Use more clear status marks
This commit is contained in:
bradley 2021-06-10 22:06:40 -04:00 committed by GitHub
commit 29f9abf35c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 20 additions and 22 deletions

View File

@ -6,12 +6,6 @@ import (
ui "github.com/gizak/termui" ui "github.com/gizak/termui"
) )
const (
mark = "◉"
healthMark = "✚"
vBar = string('\u25AE') + string('\u25AE')
)
// Status indicator // Status indicator
type Status struct { type Status struct {
*ui.Block *ui.Block
@ -22,26 +16,18 @@ type Status struct {
func NewStatus() CompactCol { func NewStatus() CompactCol {
s := &Status{ s := &Status{
Block: ui.NewBlock(), Block: ui.NewBlock(),
status: []ui.Cell{{Ch: ' '}},
health: []ui.Cell{{Ch: ' '}}, health: []ui.Cell{{Ch: ' '}},
} }
s.Height = 1 s.Height = 1
s.Border = false s.Border = false
s.setState("")
return s return s
} }
func (s *Status) Buffer() ui.Buffer { func (s *Status) Buffer() ui.Buffer {
buf := s.Block.Buffer() buf := s.Block.Buffer()
x := 0 buf.Set(s.InnerX(), s.InnerY(), s.health[0])
for _, c := range s.health { buf.Set(s.InnerX()+2, s.InnerY(), s.status[0])
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()
}
return buf return buf
} }
@ -59,36 +45,48 @@ func (s *Status) Header() string { return "" }
func (s *Status) FixedWidth() int { return 3 } func (s *Status) FixedWidth() int { return 3 }
func (s *Status) setState(val string) { func (s *Status) setState(val string) {
// defaults
text := mark
color := ui.ColorDefault color := ui.ColorDefault
var mark string
switch val { switch val {
case "":
return
case "created":
mark = "◉"
case "running": case "running":
mark = "⏵"
color = ui.ThemeAttr("status.ok") color = ui.ThemeAttr("status.ok")
case "exited": case "exited":
mark = "⏹"
color = ui.ThemeAttr("status.danger") color = ui.ThemeAttr("status.danger")
case "paused": case "paused":
text = vBar mark = "⏸"
default:
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) { func (s *Status) setHealth(val string) {
color := ui.ColorDefault color := ui.ColorDefault
mark := healthMark var mark string
switch val { switch val {
case "": case "":
return return
case "healthy": case "healthy":
mark = "☼"
color = ui.ThemeAttr("status.ok") color = ui.ThemeAttr("status.ok")
case "unhealthy": case "unhealthy":
mark = "⚠"
color = ui.ThemeAttr("status.danger") color = ui.ThemeAttr("status.danger")
case "starting": case "starting":
mark = "◌"
color = ui.ThemeAttr("status.warn") color = ui.ThemeAttr("status.warn")
default: default:
mark = " "
log.Warningf("unknown health state string: \"%v\"", val) log.Warningf("unknown health state string: \"%v\"", val)
} }