From 25172da55571a3bbce394966934681e870cd15a8 Mon Sep 17 00:00:00 2001 From: Ryan Cavicchioni Date: Tue, 24 Mar 2020 01:35:18 -0500 Subject: [PATCH] move ls printing into separate function --- cmd/lume.go | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/cmd/lume.go b/cmd/lume.go index 07a5456..43d761b 100644 --- a/cmd/lume.go +++ b/cmd/lume.go @@ -88,19 +88,7 @@ func main() { fmt.Println(err) os.Exit(1) } - 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), - ) - } + PrintLights(lights) case "set-state": 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 { color := fc.New(fc.FgRed).SprintFunc() if s == "on" {