From 51770b80db0fe299c69bef5060662178f67eb714 Mon Sep 17 00:00:00 2001 From: Grant Ammons Date: Sun, 24 Apr 2016 13:52:46 -0400 Subject: Tabwriter is the way to go --- todo.go | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) (limited to 'todo.go') diff --git a/todo.go b/todo.go index 0f62340..190e7db 100644 --- a/todo.go +++ b/todo.go @@ -1,12 +1,37 @@ package main -import "fmt" -import "github.com/gammons/todolist/todolist" +import ( + "fmt" + "os" + "strconv" + "text/tabwriter" + + "github.com/gammons/todolist/todolist" +) func main() { store := todolist.NewFileStore() store.Load() - for _, item := range store.Data { - fmt.Println(item) + + doOutput(store.Data) +} + +func doOutput(todos []todolist.Todo) { + w := new(tabwriter.Writer) + w.Init(os.Stdout, 0, 8, 0, '\t', 0) + + for _, item := range todos { + str := strconv.Itoa(item.Id) + "\t" + completedText(item.Completed) + "\t" + item.Subject + fmt.Fprintln(w, str) + //fmt.Fprintln(w, + } + w.Flush() +} + +func completedText(completed bool) string { + if completed { + return "[x]" + } else { + return "[ ]" } } -- cgit v1.3