aboutsummaryrefslogtreecommitdiffstats
path: root/todolist/app.go
diff options
context:
space:
mode:
authorGrant Ammons <gammons@gmail.com>2017-10-03 07:20:02 -0400
committerGrant Ammons <gammons@gmail.com>2017-10-03 07:20:41 -0400
commit08deecf1954f6cf748812057ba5cdd9a0425bfc9 (patch)
tree722ccf48c7a204af8d508c2f2757f673f771915b /todolist/app.go
parent0840e7a147d8594acec63fd1ce8aba9e15472839 (diff)
Refactor the formatter to an interface and rename it
This change refactors the formatter to be an interface called Printer. `NewApp` will use the functionality of `ScreenPrinter`, which is what I refactored the old `Formatter` class into. There is a new class the implements the `Printer` interface called `MemoryPrinter`, which will simply store the `groups` as they were passed to it. This will allow tests in `app_test.go` to become much more powerful, since `App` no longer needs to be tightly coupled to printing to the screen.
Diffstat (limited to 'todolist/app.go')
-rw-r--r--todolist/app.go13
1 files changed, 8 insertions, 5 deletions
diff --git a/todolist/app.go b/todolist/app.go
index 24e2a61..ad02569 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}, false)
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) {