Add visual power indicator character
This commit is contained in:
parent
a4c305c2e9
commit
9c92d7945d
@ -12,13 +12,15 @@ import (
|
|||||||
|
|
||||||
const lumercFile string = ".lumerc"
|
const lumercFile string = ".lumerc"
|
||||||
const lumeConfigFile string = "lume.conf"
|
const lumeConfigFile string = "lume.conf"
|
||||||
|
const defaultPowerIndicator rune = '●'
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
AccessToken string `toml:"access_token"`
|
AccessToken string `toml:"access_token"`
|
||||||
OutputFormat string `toml:"output_format"`
|
OutputFormat string `toml:"output_format"`
|
||||||
Colors map[string][]float32 `toml:"colors"`
|
Colors map[string][]float32 `toml:"colors"`
|
||||||
userAgent string
|
userAgent string
|
||||||
Debug bool `toml:"debug"`
|
Debug bool `toml:"debug"`
|
||||||
|
Indicator string `toml:"indicator"`
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -33,6 +35,7 @@ func NewConfig() *Config {
|
|||||||
c.userAgent = initUserAgent()
|
c.userAgent = initUserAgent()
|
||||||
c.Debug = false
|
c.Debug = false
|
||||||
c.OutputFormat = "simple"
|
c.OutputFormat = "simple"
|
||||||
|
c.Indicator = string(defaultPowerIndicator)
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -48,6 +51,10 @@ func (c *Config) Validate() error {
|
|||||||
return errors.New("access_token is not set")
|
return errors.New("access_token is not set")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if len([]rune(c.Indicator)) != 1 {
|
||||||
|
return errors.New("indicator must be a single rune")
|
||||||
|
}
|
||||||
|
|
||||||
if err = c.validateColors(); err != nil {
|
if err = c.validateColors(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
12
cmd/print.go
12
cmd/print.go
@ -102,6 +102,15 @@ func (tp *tablePrinter) Lights(lights []lifx.Light) {
|
|||||||
table.Render()
|
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 {
|
func ColorizePower(s string) string {
|
||||||
c := color.New(color.FgRed)
|
c := color.New(color.FgRed)
|
||||||
if s == "on" {
|
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) {
|
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 {
|
for _, l := range lights {
|
||||||
rows = append(rows, []string{
|
rows = append(rows, []string{
|
||||||
|
fmt.Sprint(ColorizeIndicator(l.Power)),
|
||||||
fmt.Sprint(l.Id),
|
fmt.Sprint(l.Id),
|
||||||
fmt.Sprint(l.Location.Name),
|
fmt.Sprint(l.Location.Name),
|
||||||
fmt.Sprint(l.Group.Name),
|
fmt.Sprint(l.Group.Name),
|
||||||
|
@ -39,12 +39,13 @@ func ShowCmd(ctx Context) (int, error) {
|
|||||||
for i, l := range lights {
|
for i, l := range lights {
|
||||||
indent = 0
|
indent = 0
|
||||||
fmt.Printf(
|
fmt.Printf(
|
||||||
"Light ID: %s, %s, Power: %s\n",
|
"%s Light ID: %s, %s, Power: %s\n",
|
||||||
|
ColorizeIndicator(l.Power),
|
||||||
l.Id,
|
l.Id,
|
||||||
connected(l.Connected),
|
connected(l.Connected),
|
||||||
ColorizePower(l.Power),
|
ColorizePower(l.Power),
|
||||||
)
|
)
|
||||||
indent += Tabstop
|
indent += Tabstop + 2
|
||||||
PrintfWithIndent(indent, "Label: %s, ID: %s\n", l.Label, l.Id)
|
PrintfWithIndent(indent, "Label: %s, ID: %s\n", l.Label, l.Id)
|
||||||
PrintfWithIndent(indent, "UUID: %s\n", l.UUID)
|
PrintfWithIndent(indent, "UUID: %s\n", l.UUID)
|
||||||
PrintfWithIndent(indent, "Location: %s, ID: %s\n", l.Location.Name, l.Location.Id)
|
PrintfWithIndent(indent, "Location: %s, ID: %s\n", l.Location.Name, l.Location.Id)
|
||||||
|
Loading…
Reference in New Issue
Block a user