Add visual power indicator character

This commit is contained in:
2021-04-04 23:34:52 +00:00
parent a4c305c2e9
commit 9c92d7945d
3 changed files with 22 additions and 4 deletions

View File

@ -102,6 +102,15 @@ func (tp *tablePrinter) Lights(lights []lifx.Light) {
table.Render()
}
func ColorizeIndicator(s string) string {
c := color.New(color.FgRed)
if s == "on" {
c = color.New(color.FgGreen)
}
return c.Sprint(GetConfig().Indicator)
}
func ColorizePower(s string) string {
c := color.New(color.FgRed)
if s == "on" {
@ -130,10 +139,11 @@ func PrintfWithIndent(indent int, format string, a ...interface{}) (n int, err e
}
func makeLightsTable(lights []lifx.Light) (hdr []string, rows [][]string) {
hdr = []string{"ID", "Location", "Group", "Label", "Last Seen", "Power"}
hdr = []string{"", "ID", "Location", "Group", "Label", "Last Seen", "Power"}
for _, l := range lights {
rows = append(rows, []string{
fmt.Sprint(ColorizeIndicator(l.Power)),
fmt.Sprint(l.Id),
fmt.Sprint(l.Location.Name),
fmt.Sprint(l.Group.Name),