aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorQuey-Liang Kao <s101062801@m101.nthu.edu.tw>2017-08-14 15:45:22 +0800
committerQuey-Liang Kao <s101062801@m101.nthu.edu.tw>2017-08-14 15:50:13 +0800
commit26ec23620d50be79ea664a9095b3653be79e3874 (patch)
treec7cd8f60f6c5f89850bae7db8622646ab47b86ff
parent5d28dac9b2e1d153f33551b968ab4c92cfce23ce (diff)
Implement the "ln" feature: Listing notes of a todo
-rw-r--r--todo.go5
-rw-r--r--todolist/app.go4
-rw-r--r--todolist/formatter.go11
-rw-r--r--todolist/parser.go11
4 files changed, 26 insertions, 5 deletions
diff --git a/todo.go b/todo.go
index 77faccb..e48eda2 100644
--- a/todo.go
+++ b/todo.go
@@ -123,9 +123,10 @@ func usage() {
fmt.Println("\tDeletes a todo with id 33\n")
blueBold.Println("\nManipulating notes")
- fmt.Println(" You can add additional information to a existing todo.\n")
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")
+ fmt.Println("\tLists notes of the todo with id 12\n")
blueBold.Println("\nGarbage Collection")
yellow.Println("\ttodo gc")
@@ -158,7 +159,7 @@ func routeInput(command string, input string) {
app.EditTodo(input)
case "ex", "expand":
app.ExpandTodo(input)
- case "an":
+ case "an", "ln":
app.ManipulateNotes(input)
case "gc":
app.GarbageCollect()
diff --git a/todolist/app.go b/todolist/app.go
index c2bd66a..4d526c9 100644
--- a/todolist/app.go
+++ b/todolist/app.go
@@ -143,7 +143,9 @@ func (a *App) ManipulateNotes(input string) {
retStr := parser.ParseNotes(todo, input)
if retStr != "" {
a.Save()
- fmt.Println("Notes " + retStr + "ed.")
+ if retStr != "list" {
+ fmt.Println("Notes " + retStr + "ed.")
+ }
}
}
diff --git a/todolist/formatter.go b/todolist/formatter.go
index c0f3313..847be04 100644
--- a/todolist/formatter.go
+++ b/todolist/formatter.go
@@ -43,6 +43,17 @@ func (f *Formatter) Print() {
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 207791d..1c3b7f8 100644
--- a/todolist/parser.go
+++ b/todolist/parser.go
@@ -84,11 +84,18 @@ func (p *Parser) Contexts(input string) []string {
}
func (p *Parser) ParseNotes(todo *Todo, input string) string {
- r, _ := regexp.Compile(`(\w+) \d+\s+(.*)?`)
+ r, _ := regexp.Compile(`(\w+) \d+\s*(.*)?`)
matches := r.FindStringSubmatch(input)
- if matches[1] == "an" {
+ switch matches[1] {
+ case "an":
todo.Notes = append(todo.Notes, matches[2])
return "add"
+ case "ln":
+ groups := map[string][]*Todo{}
+ groups[""] = append(groups[""], todo)
+ formatter := NewFormatter(&GroupedTodos{Groups: groups})
+ formatter.PrintNotes()
+ return "list"
}
fmt.Println("Could not match command or id")