diff --git a/cmd/config.go b/cmd/config.go index c39b60c..0e51d28 100644 --- a/cmd/config.go +++ b/cmd/config.go @@ -12,13 +12,15 @@ import ( const lumercFile string = ".lumerc" const lumeConfigFile string = "lume.conf" +const defaultPowerIndicator rune = '●' type Config struct { AccessToken string `toml:"access_token"` OutputFormat string `toml:"output_format"` Colors map[string][]float32 `toml:"colors"` userAgent string - Debug bool `toml:"debug"` + Debug bool `toml:"debug"` + Indicator string `toml:"indicator"` } var ( @@ -33,6 +35,7 @@ func NewConfig() *Config { c.userAgent = initUserAgent() c.Debug = false c.OutputFormat = "simple" + c.Indicator = string(defaultPowerIndicator) return c } @@ -48,6 +51,10 @@ func (c *Config) Validate() error { 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 { return err } diff --git a/cmd/print.go b/cmd/print.go index d590116..942ac1e 100644 --- a/cmd/print.go +++ b/cmd/print.go @@ -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), diff --git a/cmd/show.go b/cmd/show.go index 9def9aa..975b163 100644 --- a/cmd/show.go +++ b/cmd/show.go @@ -39,12 +39,13 @@ func ShowCmd(ctx Context) (int, error) { for i, l := range lights { indent = 0 fmt.Printf( - "Light ID: %s, %s, Power: %s\n", + "%s Light ID: %s, %s, Power: %s\n", + ColorizeIndicator(l.Power), l.Id, connected(l.Connected), ColorizePower(l.Power), ) - indent += Tabstop + indent += Tabstop + 2 PrintfWithIndent(indent, "Label: %s, ID: %s\n", l.Label, l.Id) PrintfWithIndent(indent, "UUID: %s\n", l.UUID) PrintfWithIndent(indent, "Location: %s, ID: %s\n", l.Location.Name, l.Location.Id)