mirror of
https://github.com/bcicen/ctop.git
synced 2025-12-06 15:16:41 +08:00
status.go: make logic more explicit
This commit is contained in:
@@ -22,11 +22,11 @@ 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
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -51,17 +51,25 @@ 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 text string
|
||||||
|
|
||||||
switch val {
|
switch val {
|
||||||
|
case "":
|
||||||
|
return
|
||||||
|
case "created":
|
||||||
|
text = mark
|
||||||
case "running":
|
case "running":
|
||||||
|
text = mark
|
||||||
color = ui.ThemeAttr("status.ok")
|
color = ui.ThemeAttr("status.ok")
|
||||||
case "exited":
|
case "exited":
|
||||||
|
text = mark
|
||||||
color = ui.ThemeAttr("status.danger")
|
color = ui.ThemeAttr("status.danger")
|
||||||
case "paused":
|
case "paused":
|
||||||
text = vBar
|
text = vBar
|
||||||
|
default:
|
||||||
|
text = " "
|
||||||
|
log.Warningf("unknown status string: \"%v\"", val)
|
||||||
}
|
}
|
||||||
|
|
||||||
s.status = ui.TextCells(text, color, ui.ColorDefault)
|
s.status = ui.TextCells(text, color, ui.ColorDefault)
|
||||||
@@ -69,18 +77,22 @@ func (s *Status) setState(val string) {
|
|||||||
|
|
||||||
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 = healthMark
|
||||||
color = ui.ThemeAttr("status.ok")
|
color = ui.ThemeAttr("status.ok")
|
||||||
case "unhealthy":
|
case "unhealthy":
|
||||||
|
mark = healthMark
|
||||||
color = ui.ThemeAttr("status.danger")
|
color = ui.ThemeAttr("status.danger")
|
||||||
case "starting":
|
case "starting":
|
||||||
|
mark = healthMark
|
||||||
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)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user