move ls printing into separate function
This commit is contained in:
parent
f31fc298cd
commit
25172da555
31
cmd/lume.go
31
cmd/lume.go
@ -88,19 +88,7 @@ func main() {
|
|||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
calculateWidths(lights)
|
PrintLights(lights)
|
||||||
fmt.Printf("total %d\n", len(lights))
|
|
||||||
for _, l := range lights {
|
|
||||||
fmt.Printf(
|
|
||||||
"%*s %*s %*s %*s %*s %-*s\n",
|
|
||||||
idWidth, l.Id,
|
|
||||||
locationWidth, l.Location.Name,
|
|
||||||
groupWidth, l.Group.Name,
|
|
||||||
labelWidth, l.Label,
|
|
||||||
lastSeenWidth, l.LastSeen.Local().Format(time.RFC3339),
|
|
||||||
powerWidth, PowerColor(l.Power),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
case "set-state":
|
case "set-state":
|
||||||
setStateCommand.Parse(os.Args[4:])
|
setStateCommand.Parse(os.Args[4:])
|
||||||
|
|
||||||
@ -215,6 +203,23 @@ func calculateWidths(lights []lifx.Light) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func PrintLights(lights []lifx.Light) {
|
||||||
|
calculateWidths(lights)
|
||||||
|
|
||||||
|
fmt.Printf("total %d\n", len(lights))
|
||||||
|
for _, l := range lights {
|
||||||
|
fmt.Printf(
|
||||||
|
"%*s %*s %*s %*s %*s %-*s\n",
|
||||||
|
idWidth, l.Id,
|
||||||
|
locationWidth, l.Location.Name,
|
||||||
|
groupWidth, l.Group.Name,
|
||||||
|
labelWidth, l.Label,
|
||||||
|
lastSeenWidth, l.LastSeen.Local().Format(time.RFC3339),
|
||||||
|
powerWidth, PowerColor(l.Power),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func PowerColor(s string) string {
|
func PowerColor(s string) string {
|
||||||
color := fc.New(fc.FgRed).SprintFunc()
|
color := fc.New(fc.FgRed).SprintFunc()
|
||||||
if s == "on" {
|
if s == "on" {
|
||||||
|
Loading…
Reference in New Issue
Block a user