Files
ctop/cwidgets/compact/text.go
T

59 lines
1.1 KiB
Go
Raw Normal View History

2017-03-03 07:57:26 +00:00
package compact
import (
ui "github.com/gizak/termui"
)
type TextCol struct {
*ui.Par
2017-08-23 22:38:14 +03:00
isHighlight bool
2017-03-03 07:57:26 +00:00
}
func NewTextCol(s string) *TextCol {
p := ui.NewPar(s)
p.Border = false
p.Height = 1
p.Width = 20
2017-08-23 22:38:14 +03:00
return &TextCol{p, false}
2017-03-03 07:57:26 +00:00
}
2017-03-03 08:02:08 +00:00
func (w *TextCol) Highlight() {
2017-08-27 23:46:01 +00:00
if w.TextFgColor == ui.ThemeAttr("par.text.fg") {
2017-08-23 22:38:14 +03:00
w.TextFgColor = ui.ThemeAttr("par.text.hi")
}
2017-03-03 08:02:08 +00:00
w.TextBgColor = ui.ThemeAttr("par.text.fg")
2017-08-23 22:38:14 +03:00
w.isHighlight = true
2017-03-03 08:02:08 +00:00
}
func (w *TextCol) UnHighlight() {
2017-08-27 23:46:01 +00:00
if w.TextFgColor == ui.ThemeAttr("par.text.hi") {
2017-08-23 22:38:14 +03:00
w.TextFgColor = ui.ThemeAttr("par.text.fg")
}
2017-03-03 08:02:08 +00:00
w.TextBgColor = ui.ThemeAttr("par.text.bg")
2017-08-23 22:38:14 +03:00
w.isHighlight = false
2017-03-03 08:02:08 +00:00
}
2017-03-03 07:57:26 +00:00
func (w *TextCol) Reset() {
w.Text = "-"
}
func (w *TextCol) Set(s string) {
w.Text = s
}
2017-08-23 22:38:14 +03:00
2017-08-27 23:46:01 +00:00
func (w *TextCol) Color(s string) {
2017-08-23 22:38:14 +03:00
color := ui.ThemeAttr("par.text.fg")
2017-08-27 23:46:01 +00:00
if w.isHighlight {
2017-08-23 22:38:14 +03:00
color = ui.ThemeAttr("par.text.hi")
}
switch s {
case "healthy":
2017-08-27 23:46:01 +00:00
color = ui.ThemeAttr("status.ok")
2017-08-23 22:38:14 +03:00
case "unhealthy":
2017-08-27 23:46:01 +00:00
color = ui.ThemeAttr("status.danger")
2017-08-23 22:38:14 +03:00
case "starting":
2017-08-27 23:46:01 +00:00
color = ui.ThemeAttr("status.warn")
2017-08-23 22:38:14 +03:00
}
w.TextFgColor = color
}