github.com/kcmerrill/alfred@v0.0.0-20180727171036-06445dcb5e3d/pkg/alfred/list.go (about) 1 package alfred 2 3 import ( 4 "fmt" 5 "sort" 6 ) 7 8 func list(context *Context, tasks map[string]Task) { 9 maxLabel := 0 10 maxSummary := 0 11 labels := make([]string, 0) 12 for label, task := range tasks { 13 // lets add the label to the list(so we an alphabatize the list) 14 labels = append(labels, label) 15 16 // figure out max label size 17 if len(label) >= maxLabel { 18 maxLabel = len(label) 19 } 20 21 // figure out max summary size 22 if len(task.Summary) >= maxSummary { 23 maxSummary = len(task.Summary) 24 } 25 } 26 27 // alphabatize the list 28 sort.Strings(labels) 29 30 noLabels := 0 31 // insignifigant tasks 32 // still chewing on this one. Not sure if we should include them or not 33 /*for _, label := range labels { 34 task := tasks[label] 35 if task.Summary == "" { 36 noLabels++ 37 fmt.Print(translate("{{ .Text.Grey }}"+label+"{{ .Text.Reset }}", emptyContext()), "\t") 38 } 39 }*/ 40 41 if noLabels != 0 { 42 // TODO: we need to determine if we should show this or not 43 fmt.Println() 44 } 45 46 // signifigant tasks 47 for _, label := range labels { 48 task := tasks[label] 49 if !task.IsPrivate() { 50 fmt.Print(translate(" {{ .Text.Task }}"+padRight(label, maxLabel, " "), context)) 51 fmt.Println(translate("{{ .Text.Grey }} | {{ .Text.Reset }}"+padRight(task.Summary, maxSummary, " "), context)) 52 } 53 } 54 }