diff options
| author | Grant Ammons <gammons@gmail.com> | 2016-04-24 13:52:46 -0400 |
|---|---|---|
| committer | Grant Ammons <gammons@gmail.com> | 2016-04-24 13:52:46 -0400 |
| commit | 51770b80db0fe299c69bef5060662178f67eb714 (patch) | |
| tree | 9a1b714ed68049d04a20409ba384eaa3a4c6a823 | |
| parent | 63893587cb41a1980318b60bf05fafbf433a24ab (diff) | |
Tabwriter is the way to go
| -rw-r--r-- | todo.go | 33 |
1 files changed, 29 insertions, 4 deletions
@@ -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 "[ ]" } } |
