aboutsummaryrefslogtreecommitdiffstats
path: root/todo.go
diff options
context:
space:
mode:
authorGrant Ammons <gammons@gmail.com>2016-04-24 13:52:46 -0400
committerGrant Ammons <gammons@gmail.com>2016-04-24 13:52:46 -0400
commit51770b80db0fe299c69bef5060662178f67eb714 (patch)
tree9a1b714ed68049d04a20409ba384eaa3a4c6a823 /todo.go
parent63893587cb41a1980318b60bf05fafbf433a24ab (diff)
Tabwriter is the way to go
Diffstat (limited to 'todo.go')
-rw-r--r--todo.go33
1 files changed, 29 insertions, 4 deletions
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 "[ ]"
}
}