From d11bf67196702892ebd5277230e98153d14c60f4 Mon Sep 17 00:00:00 2001 From: Brian Buller Date: Wed, 20 Feb 2019 07:49:41 -0600 Subject: [PATCH] More Progress * List by default, UI only if specified * Archive tasks to done list * Fix filter --- app_state.go | 2 +- main.go | 4 ++-- model.go | 8 ++++--- screen_main.go | 60 +++++++++++++++++++++++++++++--------------------- screen_task.go | 2 +- task_ops.go | 2 +- 6 files changed, 45 insertions(+), 33 deletions(-) diff --git a/app_state.go b/app_state.go index b0ec740..327bdad 100644 --- a/app_state.go +++ b/app_state.go @@ -5,7 +5,7 @@ import ( "os" "strings" - todotxt "github.com/JamesClonk/go-todotxt" + todotxt "github.com/br0xen/go-todotxt" "github.com/br0xen/user-config" ) diff --git a/main.go b/main.go index 74f8721..fe6d9af 100644 --- a/main.go +++ b/main.go @@ -18,8 +18,8 @@ func main() { if len(os.Args) > 1 { parms = os.Args[1:] } else { - // If no parameters were passed, just do an ls - parms = append(parms, "ui") + // If no parameters were passed, do a list + parms = append(parms, "ls") } os.Exit(app.run(parms)) } diff --git a/model.go b/model.go index ff2fff5..3238f68 100644 --- a/model.go +++ b/model.go @@ -4,7 +4,7 @@ import ( "strings" "time" - todotxt "github.com/JamesClonk/go-todotxt" + todotxt "github.com/br0xen/go-todotxt" ) func (a *AppState) addTask(taskString string) error { @@ -39,9 +39,11 @@ func (a *AppState) archiveTask(id int) error { if task, err = a.TaskList.GetTask(id); err != nil { return err } - a.TaskList.RemoveTask(*task) task.Completed = true - a.DoneList.AddTask(task) + if err := a.TaskList.ArchiveTaskToFile(*task, app.getDoneFile()); err != nil { + return err + } + a.TaskList.RemoveTask(*task) return nil } diff --git a/screen_main.go b/screen_main.go index 0d365d4..debdf11 100644 --- a/screen_main.go +++ b/screen_main.go @@ -5,7 +5,7 @@ import ( "strings" "time" - todotxt "github.com/JamesClonk/go-todotxt" + todotxt "github.com/br0xen/go-todotxt" "github.com/br0xen/termbox-util" termbox "github.com/nsf/termbox-go" ) @@ -159,15 +159,15 @@ func (screen *MainScreen) handleConfirmKeyEvent(event termbox.Event) int { } func (screen *MainScreen) handleInputKeyEvent(event termbox.Event) int { - screen.inputField.SetID("add task") id := screen.inputField.GetID() if id == "filter" { if event.Key == termbox.KeyEnter { // Apply the filter - screen.backspaceDoes = MainBackspaceFilter - screen.reloadList(screen.buildBundle(screen.currentList, screen.inputField.GetValue())) + filter := screen.inputField.GetValue() screen.inputField.SetID("") screen.inputField.SetValue("") + screen.backspaceDoes = MainBackspaceFilter + screen.reloadList(screen.buildBundle(screen.currentList, filter)) return ScreenMain } } else if id == "add task" { @@ -177,13 +177,13 @@ func (screen *MainScreen) handleInputKeyEvent(event termbox.Event) int { if err != nil { screen.setMessage(err.Error()) } + screen.inputField.SetID("") + screen.inputField.SetValue("") if err = app.WriteList(); err != nil { screen.setMessage(err.Error()) return ScreenMain } screen.reloadList(screen.buildBundle(screen.currentList, screen.currentFilter)) - screen.inputField.SetID("") - screen.inputField.SetValue("") return ScreenMain } } @@ -211,12 +211,20 @@ func (screen *MainScreen) drawScreen() { screen.setMessageWithTimeout("Press '?' for help", -1) } screen.drawHeader() + topId := 0 + for _, v := range screen.displayList { + if v.Id > topId { + topId = v.Id + } + } + padCnt := fmt.Sprintf("%d", topId) for k, v := range screen.displayList { + pad := strings.Repeat(" ", len(padCnt)-len(fmt.Sprintf("%d", v.Id))) useFg, useBg := DefaultFg, DefaultBg if k == screen.viewPort.cursor { useFg, useBg = CursorFg, CursorBg } - termboxUtil.DrawStringAtPoint(app.getTaskString(v), 0, k+1, useFg, useBg) + termboxUtil.DrawStringAtPoint(pad+app.getTaskString(v), 0, k+1, useFg, useBg) } screen.drawFooter() } @@ -249,25 +257,27 @@ func (screen *MainScreen) drawFooter() { } func (screen *MainScreen) archiveCurrentItem() int { - /* - // Find the task under the cursor - if len(screen.displayList) > screen.viewPort.cursor { - t := screen.displayList[screen.viewPort.cursor] - // Load the task screen with this task - if err := a.archiveTask(t.Id); err != nil { - screen.setMessage(error.Error()) - } - - - - b := Bundle{} - b.setValue(TaskBundleTaskIdKey, t.Id) - if err := app.screens[ScreenTask].initialize(b); err != nil { - screen.setMessage(err.Error()) - } - return ScreenTask + if screen.currentList != MainBundleListTodo { + screen.setMessage("Task is already archived") + return ScreenMain + } + // Find the task under the cursor + if len(screen.displayList) > screen.viewPort.cursor { + t := screen.displayList[screen.viewPort.cursor] + if err := app.archiveTask(t.Id); err != nil { + screen.setMessage(err.Error()) + return ScreenMain } - */ + if err := app.WriteList(); err != nil { + screen.setMessage(err.Error()) + return ScreenMain + } + // Reload the list + b := screen.buildBundle(screen.currentList, screen.currentFilter) + if err := screen.reloadList(b); err != nil { + screen.setMessage(err.Error()) + } + } return ScreenMain } diff --git a/screen_task.go b/screen_task.go index badf3d8..c6e5d0b 100644 --- a/screen_task.go +++ b/screen_task.go @@ -6,7 +6,7 @@ import ( "strings" "time" - todotxt "github.com/JamesClonk/go-todotxt" + todotxt "github.com/br0xen/go-todotxt" "github.com/br0xen/termbox-util" termbox "github.com/nsf/termbox-go" ) diff --git a/task_ops.go b/task_ops.go index 178d322..e17d3e4 100644 --- a/task_ops.go +++ b/task_ops.go @@ -5,7 +5,7 @@ import ( "strconv" "strings" - todotxt "github.com/JamesClonk/go-todotxt" + todotxt "github.com/br0xen/go-todotxt" ) func (a *AppState) opListTasks(args []string) int {