aboutsummaryrefslogtreecommitdiffstats
path: root/todolist/formatter.go
diff options
context:
space:
mode:
authorGrant Ammons <gammons@gmail.com>2016-04-25 14:35:43 -0400
committerGrant Ammons <gammons@gmail.com>2016-04-25 14:35:43 -0400
commita0f7203996439210b2a40663eeeeb8563ab03d68 (patch)
tree84f7bd055f5cc581fa2b4894206868c998512d1a /todolist/formatter.go
parentdde4f5330c2126af0e3ec17e4098653c6f551426 (diff)
Get grouping working correctly
Diffstat (limited to 'todolist/formatter.go')
-rw-r--r--todolist/formatter.go26
1 files changed, 16 insertions, 10 deletions
diff --git a/todolist/formatter.go b/todolist/formatter.go
index b2b9816..77006e0 100644
--- a/todolist/formatter.go
+++ b/todolist/formatter.go
@@ -12,25 +12,31 @@ import (
)
type Formatter struct {
- Todos []Todo
- Writer *tabwriter.Writer
+ GroupedTodos *GroupedTodos
+ Writer *tabwriter.Writer
}
-func NewFormatter(todos []Todo) *Formatter {
+func NewFormatter(todos *GroupedTodos) *Formatter {
w := new(tabwriter.Writer)
w.Init(os.Stdout, 0, 8, 0, '\t', 0)
- formatter := &Formatter{Todos: todos, Writer: w}
+ formatter := &Formatter{GroupedTodos: todos, Writer: w}
return formatter
}
func (f *Formatter) Print() {
- for _, todo := range f.Todos {
- yellow := color.New(color.FgYellow).SprintFunc()
+ yellow := color.New(color.FgYellow).SprintFunc()
+ cyan := color.New(color.FgCyan).SprintFunc()
+
+ for key, todos := range f.GroupedTodos.Groups {
+ fmt.Fprintf(f.Writer, "\n \t%s\n", cyan(key))
+
+ for _, todo := range todos {
+ fmt.Fprintf(f.Writer, " \t%s\t%s\t%s\t\n",
+ yellow(strconv.Itoa(todo.Id)),
+ f.formatCompleted(todo.Completed),
+ f.formatSubject(todo.Subject))
+ }
- fmt.Fprintf(f.Writer, " \t%s\t%s\t%s\t\n",
- yellow(strconv.Itoa(todo.Id)),
- f.formatCompleted(todo.Completed),
- f.formatSubject(todo.Subject))
}
f.Writer.Flush()
}