diff options
| author | Quey-Liang Kao <s101062801@m101.nthu.edu.tw> | 2017-08-20 22:45:31 +0800 |
|---|---|---|
| committer | Quey-Liang Kao <s101062801@m101.nthu.edu.tw> | 2017-08-20 22:45:31 +0800 |
| commit | 34639c4285621177efb10b82ddb07cd0017af56a (patch) | |
| tree | 6a3828ef5f1af8a2bcf74a03eabe33f896a3dbf7 | |
| parent | ebc7b53438ef6328baf813c7cad19e43839ad0f1 (diff) | |
Redefine sub-commands: "ln" and "n"
Sub-command "ln" is redefined to the function of listing all todos
with their notes; "n" replaces original "ln", listing the notes of
a specific todo.
| -rw-r--r-- | todo.go | 8 | ||||
| -rw-r--r-- | todolist/app.go | 3 | ||||
| -rw-r--r-- | todolist/filter.go | 4 | ||||
| -rw-r--r-- | todolist/formatter.go | 19 | ||||
| -rw-r--r-- | todolist/parser.go | 4 |
5 files changed, 18 insertions, 20 deletions
@@ -123,9 +123,11 @@ func usage() { fmt.Println("\tDeletes a todo with id 33\n") blueBold.Println("\nManipulating notes") + yellow.Println("\ttodo ln") + fmt.Println("\tlists all todos with their notes") yellow.Println("\ttodo an 12 check http://this.web.site") fmt.Println("\tAdds notes \"check http://this.web.site\" to the todo with id 12\n") - yellow.Println("\ttodo ln 12") + yellow.Println("\ttodo n 12") fmt.Println("\tLists notes of the todo with id 12\n") yellow.Println("\ttodo dn 12 3") fmt.Println("\tDeletes the 3rd note of the todo with id 12\n") @@ -143,7 +145,7 @@ func usage() { func routeInput(command string, input string) { app := todolist.NewApp() switch command { - case "l", "list", "agenda": + case "l", "ln", "list", "agenda": app.ListTodos(input) case "a", "add": app.AddTodo(input) @@ -163,7 +165,7 @@ func routeInput(command string, input string) { app.EditTodo(input) case "ex", "expand": app.ExpandTodo(input) - case "an", "ln", "dn", "en": + case "an", "n", "dn", "en": app.ManipulateNotes(input) case "gc": app.GarbageCollect() diff --git a/todolist/app.go b/todolist/app.go index 66b30c8..79e3aad 100644 --- a/todolist/app.go +++ b/todolist/app.go @@ -173,7 +173,8 @@ func (a *App) ListTodos(input string) { grouped := a.getGroups(input, filtered) formatter := NewFormatter(grouped) - formatter.Print() + re, _ := regexp.Compile(`^ln`) + formatter.Print(re.MatchString(input)) } func (a *App) PrioritizeTodo(input string) { diff --git a/todolist/filter.go b/todolist/filter.go index dd61d11..88b28a7 100644 --- a/todolist/filter.go +++ b/todolist/filter.go @@ -38,7 +38,7 @@ func (f *TodoFilter) filterArchived(input string) []*Todo { return f.Todos } - r, _ := regexp.Compile(`l archived$`) + r, _ := regexp.Compile(`ln? archived$`) if r.MatchString(input) { return f.getArchived() } else { @@ -47,7 +47,7 @@ func (f *TodoFilter) filterArchived(input string) []*Todo { } func (f *TodoFilter) filterPrioritized(input string) []*Todo { - r, _ := regexp.Compile(`l p`) + r, _ := regexp.Compile(`ln? p`) if r.MatchString(input) { return f.getPrioritized() } else { diff --git a/todolist/formatter.go b/todolist/formatter.go index 847be04..e7863db 100644 --- a/todolist/formatter.go +++ b/todolist/formatter.go @@ -25,7 +25,7 @@ func NewFormatter(todos *GroupedTodos) *Formatter { return formatter } -func (f *Formatter) Print() { +func (f *Formatter) Print(printNotes bool) { cyan := color.New(color.FgCyan).SprintFunc() var keys []string @@ -38,22 +38,17 @@ func (f *Formatter) Print() { fmt.Fprintf(f.Writer, "\n %s\n", cyan(key)) for _, todo := range f.GroupedTodos.Groups[key] { f.printTodo(todo) + if printNotes { + for nid, note := range todo.Notes { + fmt.Fprintf(f.Writer, " %s\t%s\t\n", + cyan(strconv.Itoa(nid)), note) + } + } } } f.Writer.Flush() } -func (f *Formatter) PrintNotes() { - cyan := color.New(color.FgCyan).SprintFunc() - todo := f.GroupedTodos.Groups[""][0] - f.printTodo(todo) - for nid, note := range todo.Notes { - fmt.Fprintf(f.Writer, " %s\t%s\t\n", - cyan(strconv.Itoa(nid)), note) - } - f.Writer.Flush() -} - func (f *Formatter) printTodo(todo *Todo) { yellow := color.New(color.FgYellow) if todo.IsPriority { diff --git a/todolist/parser.go b/todolist/parser.go index 42af133..8f5e180 100644 --- a/todolist/parser.go +++ b/todolist/parser.go @@ -91,11 +91,11 @@ func (p *Parser) ParseNotes(todo *Todo, input string) string { todo.Notes = append(todo.Notes, matches[2]) return "add" - case "ln": + case "n": groups := map[string][]*Todo{} groups[""] = append(groups[""], todo) formatter := NewFormatter(&GroupedTodos{Groups: groups}) - formatter.PrintNotes() + formatter.Print(true) return "list" case "dn": |
