diff options
| author | Grant Ammons <gammons@gmail.com> | 2017-10-04 07:34:43 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-10-04 07:34:43 -0400 |
| commit | b3bd13d469ff1c072e5ff6dfe15267cc51e14db5 (patch) | |
| tree | 49bfa1d32b280be32ac42f1d0ddf1ef07f6809fe /todolist/app.go | |
| parent | 0840e7a147d8594acec63fd1ce8aba9e15472839 (diff) | |
| parent | 6193b27cd7c71bcff5b5dd0cafb4f04172a73206 (diff) | |
Merge pull request #109 from gammons/refactor-printer
Refactor the formatter to an interface and rename it
Diffstat (limited to 'todolist/app.go')
| -rw-r--r-- | todolist/app.go | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/todolist/app.go b/todolist/app.go index 24e2a61..5703ace 100644 --- a/todolist/app.go +++ b/todolist/app.go @@ -9,11 +9,16 @@ import ( type App struct { TodoStore Store + Printer Printer TodoList *TodoList } func NewApp() *App { - app := &App{TodoList: &TodoList{}, TodoStore: NewFileStore()} + app := &App{ + TodoList: &TodoList{}, + Printer: NewScreenPrinter(), + TodoStore: NewFileStore(), + } return app } @@ -179,8 +184,7 @@ func (a *App) HandleNotes(input string) { } else if parser.ParseShowNote(todo, input) { groups := map[string][]*Todo{} groups[""] = append(groups[""], todo) - formatter := NewFormatter(&GroupedTodos{Groups: groups}) - formatter.Print(true) + a.Printer.Print(&GroupedTodos{Groups: groups}, true) return } a.Save() @@ -202,9 +206,8 @@ func (a *App) ListTodos(input string) { filtered := NewFilter(a.TodoList.Todos()).Filter(input) grouped := a.getGroups(input, filtered) - formatter := NewFormatter(grouped) re, _ := regexp.Compile(`^ln`) - formatter.Print(re.MatchString(input)) + a.Printer.Print(grouped, re.MatchString(input)) } func (a *App) PrioritizeTodo(input string) { |
