Archive/Unarchive

Several other improvements
This commit is contained in:
Brian Buller 2019-02-21 10:47:08 -06:00
parent d8c9e1a26b
commit ff8a0ec0b7
6 changed files with 270 additions and 71 deletions

View File

@ -16,7 +16,7 @@ func (a *AppState) addTask(taskString string) error {
t.CreatedDate = time.Now() t.CreatedDate = time.Now()
} }
a.TaskList.AddTask(t) a.TaskList.AddTask(t)
return nil return a.WriteList()
} }
func (a *AppState) toggleTaskComplete(id int) error { func (a *AppState) toggleTaskComplete(id int) error {
@ -30,7 +30,7 @@ func (a *AppState) toggleTaskComplete(id int) error {
} else { } else {
task.Complete() task.Complete()
} }
return nil return a.WriteList()
} }
func (a *AppState) archiveTask(id int) error { func (a *AppState) archiveTask(id int) error {
@ -39,12 +39,25 @@ func (a *AppState) archiveTask(id int) error {
if task, err = a.TaskList.GetTask(id); err != nil { if task, err = a.TaskList.GetTask(id); err != nil {
return err return err
} }
task.Completed = true
if err := a.TaskList.ArchiveTaskToFile(*task, app.getDoneFile()); err != nil { if err := a.TaskList.ArchiveTaskToFile(*task, app.getDoneFile()); err != nil {
return err return err
} }
a.TaskList.RemoveTask(*task) a.TaskList.RemoveTask(*task)
return nil return a.WriteList()
}
func (a *AppState) unarchiveTask(id int) error {
var err error
var task *todotxt.Task
if task, err = a.DoneList.GetTask(id); err != nil {
return err
}
a.TaskList.AddTask(task)
if err = a.WriteList(); err != nil {
return err
}
a.DoneList.RemoveTask(*task)
return a.WriteDoneList()
} }
func (a *AppState) getFilterPredicate(filter string) func(todotxt.Task) bool { func (a *AppState) getFilterPredicate(filter string) func(todotxt.Task) bool {

View File

@ -25,13 +25,9 @@ const (
) )
func (a *AppState) BuildScreens() { func (a *AppState) BuildScreens() {
mainScreen := MainScreen{ mainScreen := MainScreen{}
viewPort: &ViewPort{},
}
aboutScreen := AboutScreen{} aboutScreen := AboutScreen{}
taskScreen := TaskScreen{ taskScreen := TaskScreen{}
viewPort: &ViewPort{},
}
a.screens = append(a.screens, &mainScreen) a.screens = append(a.screens, &mainScreen)
a.screens = append(a.screens, &taskScreen) a.screens = append(a.screens, &taskScreen)
a.screens = append(a.screens, &aboutScreen) a.screens = append(a.screens, &aboutScreen)
@ -47,16 +43,28 @@ func (a *AppState) layoutAndDrawScreen(s Screen) {
termbox.Flush() termbox.Flush()
} }
// ViewPort helps keep track of what's being displayed on the screen
type ViewPort struct {
bytesPerRow int
numberOfRows int
firstRow int
cursor int
}
func readUserInput(e chan termbox.Event) { func readUserInput(e chan termbox.Event) {
for { for {
e <- termbox.PollEvent() e <- termbox.PollEvent()
} }
} }
func refreshList(e chan termbox.Event) {
/*
for {
time.Sleep(5 * time.Minute)
app.LoadTasklist()
app.LoadDoneList()
e <- termbox.Event{Type: termbox.EventNone}
}
*/
}
/*
* ViewPort helps keep track of what's being displayed on the screen
*/
type ViewPort struct {
bytesPerRow int
numberOfRows int
firstRow int
}

View File

@ -1,6 +1,7 @@
package main package main
import ( import (
"fmt"
"time" "time"
"github.com/br0xen/termbox-util" "github.com/br0xen/termbox-util"
@ -9,13 +10,48 @@ import (
// AboutScreen holds all that's going on // AboutScreen holds all that's going on
type AboutScreen struct { type AboutScreen struct {
viewPort *ViewPort viewPort ViewPort
message string message string
messageTimeout time.Duration messageTimeout time.Duration
messageTime time.Time messageTime time.Time
titleTemplate []string
commandsCol1 []Command
commandsCol2 []Command
}
type Command struct {
key string
description string
} }
func (screen *AboutScreen) initialize(bundle Bundle) error { func (screen *AboutScreen) initialize(bundle Bundle) error {
screen.titleTemplate = []string{
" __ ",
" _________ _____| | __",
" / ___\\__ \\ / ___/ |/ /",
" / /_/ > __ \\_\\___ \\| < ",
" \\___ (____ /____ >__|_ \\",
"/_____/ \\/ \\/ \\/",
}
screen.commandsCol1 = []Command{
Command{"j,↓", "down"},
Command{"k,↑", "up"},
Command{"l,→", "open task"},
Command{"g", "goto top"},
Command{"G", "goto bottom"},
Command{"ctrl+f", "jump down"},
Command{"ctrl+b", "jump up"},
}
screen.commandsCol2 = []Command{
Command{"r", "rename pair/bucket"},
Command{"D", "move task to done.txt"},
Command{"x,X", "export as string/json to file"},
Command{"?", "this screen"},
Command{"q", "quit program"},
}
return nil return nil
} }
@ -25,6 +61,36 @@ func (screen *AboutScreen) handleKeyEvent(event termbox.Event) int {
func (screen *AboutScreen) drawScreen() { func (screen *AboutScreen) drawScreen() {
width, height := termbox.Size() width, height := termbox.Size()
exitTxt := "Press any key to return to tasks" xPos := (width - len(screen.titleTemplate[0])) / 2
yPos := 1
for _, line := range screen.titleTemplate {
termboxUtil.DrawStringAtPoint(line, xPos, yPos, DefaultFg, DefaultBg)
yPos++
}
numCols := 2
if width < 80 {
numCols = 1
}
col1XPos := (width - (width * 3 / 4))
col2XPos := (width - (width * 2 / 4))
if numCols == 1 {
col2XPos = col1XPos
}
screen.drawCommandsAtPoint(screen.commandsCol1, col1XPos, yPos)
screen.drawCommandsAtPoint(screen.commandsCol2, col2XPos, yPos)
exitTxt := "Press any key to return to tasks " + fmt.Sprintf("%d", width)
termboxUtil.DrawStringAtPoint(exitTxt, (width-len(exitTxt))/2, height-1, TitleFg, TitleBg) termboxUtil.DrawStringAtPoint(exitTxt, (width-len(exitTxt))/2, height-1, TitleFg, TitleBg)
} }
func (screen *AboutScreen) drawCommandsAtPoint(commands []Command, x, y int) {
xPos, yPos := x, y
for index, cmd := range commands {
termboxUtil.DrawStringAtPoint(fmt.Sprintf("%6s", cmd.key), xPos, yPos, DefaultFg, DefaultBg)
termboxUtil.DrawStringAtPoint(cmd.description, xPos+8, yPos, DefaultFg, DefaultBg)
yPos++
if index > 2 && index%2 == 1 {
yPos++
}
}
}

View File

@ -12,11 +12,12 @@ import (
// MainScreen holds all that's going on // MainScreen holds all that's going on
type MainScreen struct { type MainScreen struct {
viewPort *ViewPort viewPort ViewPort
message string message string
messageTimeout time.Duration messageTimeout time.Duration
messageTime time.Time messageTime time.Time
mode int mode int
cursor map[string]int
inputField *termboxUtil.InputField inputField *termboxUtil.InputField
@ -43,16 +44,25 @@ const (
MainBackspaceNothing = iota MainBackspaceNothing = iota
MainBackspaceMain MainBackspaceMain
MainBackspaceFilter MainBackspaceFilter
InputIDFilter = "filter"
InputIDAddTask = "add task"
InputIDIncompleteArchive = "archive incomplete task? (y/n)"
InputIDUnArchiveTask = "move task to active list? (y/n)"
) )
func (screen *MainScreen) initialize(bundle Bundle) error { func (screen *MainScreen) initialize(bundle Bundle) error {
width, height := termbox.Size()
screen.inputField = termboxUtil.CreateInputField(0, (height - 3), width, 1, DefaultFg, DefaultBg)
screen.cursor = make(map[string]int)
if bundle != nil {
if err := screen.reloadList(bundle); err != nil { if err := screen.reloadList(bundle); err != nil {
return err return err
} }
width, height := termbox.Size()
screen.inputField = termboxUtil.CreateInputField(0, (height - 3), width, 1, DefaultFg, DefaultBg)
screen.inputField.SetID("") screen.inputField.SetID("")
screen.inputField.SetBordered(false) screen.inputField.SetBordered(false)
}
return nil return nil
} }
@ -99,6 +109,9 @@ func (screen *MainScreen) reloadList(bundle Bundle) error {
} }
} }
} }
if screen.cursor[screen.currentList] > len(screen.displayList)-1 {
screen.cursor[screen.currentList] = len(screen.displayList) - 1
}
return nil return nil
} }
@ -108,6 +121,10 @@ func (screen *MainScreen) handleKeyEvent(event termbox.Event) int {
} }
if event.Ch == '?' { if event.Ch == '?' {
// Go to About Screen // Go to About Screen
b := Bundle{}
if err := app.screens[ScreenAbout].initialize(b); err != nil {
screen.setMessage(err.Error())
}
return ScreenAbout return ScreenAbout
} else if event.Key == termbox.KeyBackspace || event.Key == termbox.KeyBackspace2 { } else if event.Key == termbox.KeyBackspace || event.Key == termbox.KeyBackspace2 {
@ -127,13 +144,35 @@ func (screen *MainScreen) handleKeyEvent(event termbox.Event) int {
} else if event.Key == termbox.KeySpace { } else if event.Key == termbox.KeySpace {
return screen.toggleTaskComplete() return screen.toggleTaskComplete()
} else if event.Ch == 'g' {
screen.cursor[screen.currentList] = 0
} else if event.Ch == 'G' {
screen.cursor[screen.currentList] = len(screen.displayList) - 1
} else if event.Key == termbox.KeyCtrlF {
// Jump forward half a screen
_, h := termbox.Size()
screen.cursor[screen.currentList] += (h / 2)
if screen.cursor[screen.currentList] >= len(screen.displayList) {
screen.cursor[screen.currentList] = len(screen.displayList) - 1
}
} else if event.Key == termbox.KeyCtrlB {
// Jump back half a screen
_, h := termbox.Size()
screen.cursor[screen.currentList] -= (h / 2)
if screen.cursor[screen.currentList] < 0 {
screen.cursor[screen.currentList] = 0
}
} else if event.Ch == 'L' { } else if event.Ch == 'L' {
return screen.toggleViewList() return screen.toggleViewList()
} else if event.Ch == 'a' { } else if event.Ch == 'a' {
return screen.startAddNewTask() return screen.startAddNewTask()
} else if event.Ch == 'e' || event.Ch == 'l' || event.Key == termbox.KeyEnter { } else if event.Ch == 'l' || event.Key == termbox.KeyEnter || event.Key == termbox.KeyArrowRight {
return screen.startEditTaskScreen() return screen.startEditTaskScreen()
} else if event.Ch == 'j' || event.Key == termbox.KeyArrowDown { } else if event.Ch == 'j' || event.Key == termbox.KeyArrowDown {
@ -146,7 +185,7 @@ func (screen *MainScreen) handleKeyEvent(event termbox.Event) int {
screen.startFilter() screen.startFilter()
} else if event.Ch == 'D' { } else if event.Ch == 'D' {
screen.archiveCurrentItem() screen.confirmArchiveItem()
} else if event.Ch == 'q' { } else if event.Ch == 'q' {
return ScreenExit return ScreenExit
@ -154,13 +193,9 @@ func (screen *MainScreen) handleKeyEvent(event termbox.Event) int {
return ScreenMain return ScreenMain
} }
func (screen *MainScreen) handleConfirmKeyEvent(event termbox.Event) int {
return ScreenMain
}
func (screen *MainScreen) handleInputKeyEvent(event termbox.Event) int { func (screen *MainScreen) handleInputKeyEvent(event termbox.Event) int {
id := screen.inputField.GetID() switch screen.inputField.GetID() {
if id == "filter" { case InputIDFilter:
if event.Key == termbox.KeyEnter { if event.Key == termbox.KeyEnter {
// Apply the filter // Apply the filter
filter := screen.inputField.GetValue() filter := screen.inputField.GetValue()
@ -170,7 +205,7 @@ func (screen *MainScreen) handleInputKeyEvent(event termbox.Event) int {
screen.reloadList(screen.buildBundle(screen.currentList, filter)) screen.reloadList(screen.buildBundle(screen.currentList, filter))
return ScreenMain return ScreenMain
} }
} else if id == "add task" { case InputIDAddTask:
if event.Key == termbox.KeyEnter { if event.Key == termbox.KeyEnter {
// Create the new item // Create the new item
err := app.addTask(screen.inputField.GetValue()) err := app.addTask(screen.inputField.GetValue())
@ -179,13 +214,28 @@ func (screen *MainScreen) handleInputKeyEvent(event termbox.Event) int {
} }
screen.inputField.SetID("") screen.inputField.SetID("")
screen.inputField.SetValue("") screen.inputField.SetValue("")
if err = app.WriteList(); err != nil {
screen.setMessage(err.Error())
return ScreenMain
}
screen.reloadList(screen.buildBundle(screen.currentList, screen.currentFilter)) screen.reloadList(screen.buildBundle(screen.currentList, screen.currentFilter))
return ScreenMain return ScreenMain
} }
case InputIDIncompleteArchive:
if event.Ch == 'y' || event.Ch == 'Y' {
return screen.archiveCurrentItem()
}
screen.inputField.SetID("")
screen.inputField.SetValue("")
screen.reloadList(screen.buildBundle(screen.currentList, screen.currentFilter))
return ScreenMain
case InputIDUnArchiveTask:
if event.Ch == 'y' || event.Ch == 'Y' {
screen.inputField.SetID("")
screen.inputField.SetValue("")
screen.reloadList(screen.buildBundle(screen.currentList, screen.currentFilter))
return screen.unarchiveCurrentItem()
}
screen.inputField.SetID("")
screen.inputField.SetValue("")
screen.reloadList(screen.buildBundle(screen.currentList, screen.currentFilter))
return ScreenMain
} }
if event.Key == termbox.KeyBackspace || event.Key == termbox.KeyBackspace2 { if event.Key == termbox.KeyBackspace || event.Key == termbox.KeyBackspace2 {
if screen.inputField.GetValue() == "" { if screen.inputField.GetValue() == "" {
@ -194,6 +244,11 @@ func (screen *MainScreen) handleInputKeyEvent(event termbox.Event) int {
screen.inputField.SetValue("") screen.inputField.SetValue("")
return ScreenMain return ScreenMain
} }
} else if event.Key == termbox.KeyEsc {
screen.reloadList(screen.buildBundle(screen.currentList, screen.currentFilter))
screen.inputField.SetID("")
screen.inputField.SetValue("")
return ScreenMain
} }
screen.inputField.HandleEvent(event) screen.inputField.HandleEvent(event)
return ScreenMain return ScreenMain
@ -207,6 +262,18 @@ func (screen *MainScreen) setActiveList(list todotxt.TaskList) {
} }
func (screen *MainScreen) drawScreen() { func (screen *MainScreen) drawScreen() {
_, height := termbox.Size()
screen.viewPort.numberOfRows = height - 1
if screen.inputField.GetID() != "" {
screen.viewPort.numberOfRows--
}
screen.viewPort.firstRow = 1
displayOffset := 0
maxCursor := screen.viewPort.numberOfRows * 2 / 3
if screen.cursor[screen.currentList] > maxCursor {
displayOffset = screen.cursor[screen.currentList] - maxCursor
}
if screen.message == "" { if screen.message == "" {
screen.setMessageWithTimeout("Press '?' for help", -1) screen.setMessageWithTimeout("Press '?' for help", -1)
} }
@ -221,10 +288,13 @@ func (screen *MainScreen) drawScreen() {
for k, v := range screen.displayList { for k, v := range screen.displayList {
pad := strings.Repeat(" ", len(padCnt)-len(fmt.Sprintf("%d", v.Id))) pad := strings.Repeat(" ", len(padCnt)-len(fmt.Sprintf("%d", v.Id)))
useFg, useBg := DefaultFg, DefaultBg useFg, useBg := DefaultFg, DefaultBg
if k == screen.viewPort.cursor { if k == screen.cursor[screen.currentList] {
useFg, useBg = CursorFg, CursorBg useFg, useBg = CursorFg, CursorBg
} }
termboxUtil.DrawStringAtPoint(pad+app.getTaskString(v), 0, k+1, useFg, useBg) lineY := k + 1 - displayOffset
if lineY > 0 && lineY < screen.viewPort.numberOfRows {
termboxUtil.DrawStringAtPoint(pad+app.getTaskString(v), 0, lineY, useFg, useBg)
}
} }
screen.drawFooter() screen.drawFooter()
} }
@ -247,28 +317,66 @@ func (screen *MainScreen) drawFooter() {
if screen.messageTimeout > 0 && time.Since(screen.messageTime) > screen.messageTimeout { if screen.messageTimeout > 0 && time.Since(screen.messageTime) > screen.messageTimeout {
screen.clearMessage() screen.clearMessage()
} }
_, height := termbox.Size() width, height := termbox.Size()
if screen.inputField.GetID() != "" { if screen.inputField.GetID() != "" {
termboxUtil.DrawStringAtPoint(screen.inputField.GetID()+": ", 0, height-2, DefaultFg, DefaultBg) screen.inputField.SetX(len(screen.inputField.GetID()) + 2)
pad := width - len(screen.inputField.GetID()+":")
field := screen.inputField.GetID() + ":" + strings.Repeat(" ", pad)
termboxUtil.DrawStringAtPoint(field, 0, height-2, DefaultFg, DefaultBg)
screen.inputField.Draw() screen.inputField.Draw()
} }
// And the 'message' // And the 'message'
termboxUtil.DrawStringAtPoint(screen.message, 0, height-1, DefaultFg, DefaultBg) termboxUtil.DrawStringAtPoint(screen.message, 0, height-1, DefaultFg, DefaultBg)
} }
func (screen *MainScreen) confirmArchiveItem() int {
if screen.currentList != MainBundleListTodo {
screen.inputField.SetID(InputIDUnArchiveTask)
return ScreenMain
}
// Find the task under the cursor
if screen.cursor[screen.currentList] < len(screen.displayList) {
t := screen.displayList[screen.cursor[screen.currentList]]
if !t.Completed {
// Task isn't completed, verify that the user wants to archive it
screen.inputField.SetID(InputIDIncompleteArchive)
} else {
return screen.archiveCurrentItem()
}
}
return ScreenMain
}
func (screen *MainScreen) archiveCurrentItem() int { func (screen *MainScreen) archiveCurrentItem() int {
if screen.currentList != MainBundleListTodo { if screen.currentList != MainBundleListTodo {
screen.setMessage("Task is already archived") screen.setMessage("Task is already archived")
return ScreenMain return ScreenMain
} }
// Find the task under the cursor // Find the task under the cursor
if len(screen.displayList) > screen.viewPort.cursor { if len(screen.displayList) > screen.cursor[screen.currentList] {
t := screen.displayList[screen.viewPort.cursor] t := screen.displayList[screen.cursor[screen.currentList]]
if err := app.archiveTask(t.Id); err != nil { if err := app.archiveTask(t.Id); err != nil {
screen.setMessage(err.Error()) screen.setMessage(err.Error())
return ScreenMain return ScreenMain
} }
if err := app.WriteList(); err != nil { // Reload the list
b := screen.buildBundle(screen.currentList, screen.currentFilter)
if err := screen.reloadList(b); err != nil {
screen.setMessage(err.Error())
}
}
return ScreenMain
}
func (screen *MainScreen) unarchiveCurrentItem() int {
if screen.currentList == MainBundleListTodo {
screen.setMessage("Task is not archived")
return ScreenMain
}
// Find the task under the cursor
if len(screen.displayList) > screen.cursor[screen.currentList] {
t := screen.displayList[screen.cursor[screen.currentList]]
if err := app.unarchiveTask(t.Id); err != nil {
screen.setMessage(err.Error()) screen.setMessage(err.Error())
return ScreenMain return ScreenMain
} }
@ -283,8 +391,8 @@ func (screen *MainScreen) archiveCurrentItem() int {
func (screen *MainScreen) startEditTaskScreen() int { func (screen *MainScreen) startEditTaskScreen() int {
// Find the task under the cursor // Find the task under the cursor
if len(screen.displayList) > screen.viewPort.cursor { if len(screen.displayList) > screen.cursor[screen.currentList] {
t := screen.displayList[screen.viewPort.cursor] t := screen.displayList[screen.cursor[screen.currentList]]
// Load the task screen with this task // Load the task screen with this task
b := Bundle{} b := Bundle{}
b.setValue(TaskBundleTaskIdKey, t.Id) b.setValue(TaskBundleTaskIdKey, t.Id)
@ -300,7 +408,7 @@ func (screen *MainScreen) reloadCurrentView() {
bundle := Bundle{} bundle := Bundle{}
bundle.setValue(MainBundleListKey, screen.currentList) bundle.setValue(MainBundleListKey, screen.currentList)
bundle.setValue(MainBundleFilterKey, screen.currentFilter) bundle.setValue(MainBundleFilterKey, screen.currentFilter)
screen.initialize(bundle) screen.reloadList(bundle)
} }
func (screen *MainScreen) toggleViewList() int { func (screen *MainScreen) toggleViewList() int {
@ -312,54 +420,55 @@ func (screen *MainScreen) toggleViewList() int {
bundle.setValue(MainBundleListKey, MainBundleListTodo) bundle.setValue(MainBundleListKey, MainBundleListTodo)
} }
bundle.setValue(MainBundleFilterKey, screen.currentFilter) bundle.setValue(MainBundleFilterKey, screen.currentFilter)
screen.initialize(bundle) screen.reloadList(bundle)
return ScreenMain return ScreenMain
} }
func (screen *MainScreen) startAddNewTask() int { func (screen *MainScreen) startAddNewTask() int {
screen.inputField.SetID("add task") screen.inputField.SetID(InputIDAddTask)
screen.inputField.SetX(len(screen.inputField.GetID()) + 2)
return ScreenMain return ScreenMain
} }
func (screen *MainScreen) toggleTaskComplete() int { func (screen *MainScreen) toggleTaskComplete() int {
if screen.currentList == MainBundleListDone {
screen.setMessage("Task is archived, unable to modify.")
return ScreenMain
}
// Find the task under the cursor // Find the task under the cursor
if len(screen.displayList) > screen.viewPort.cursor { if len(screen.displayList) > screen.cursor[screen.currentList] {
t := screen.displayList[screen.viewPort.cursor] t := screen.displayList[screen.cursor[screen.currentList]]
err := app.toggleTaskComplete(t.Id) err := app.toggleTaskComplete(t.Id)
if err != nil { if err != nil {
screen.setMessage(err.Error()) screen.setMessage(err.Error())
return ScreenMain return ScreenMain
} }
if err = app.WriteList(); err != nil {
screen.setMessage(err.Error())
}
} }
screen.reloadCurrentView() screen.reloadCurrentView()
return ScreenMain return ScreenMain
} }
func (screen *MainScreen) moveCursorDown() bool { func (screen *MainScreen) moveCursorDown() bool {
screen.viewPort.cursor++ screen.cursor[screen.currentList]++
if screen.viewPort.cursor >= len(screen.displayList) { if screen.cursor[screen.currentList] >= len(screen.displayList) {
screen.viewPort.cursor = len(screen.displayList) - 1 screen.cursor[screen.currentList] = len(screen.displayList) - 1
return false return false
} }
return true return true
} }
func (screen *MainScreen) moveCursorUp() bool { func (screen *MainScreen) moveCursorUp() bool {
screen.viewPort.cursor-- screen.cursor[screen.currentList]--
if screen.viewPort.cursor < 0 { if screen.cursor[screen.currentList] < 0 {
screen.viewPort.cursor = 0 screen.cursor[screen.currentList] = 0
return false return false
} }
return true return true
} }
func (screen *MainScreen) startFilter() { func (screen *MainScreen) startFilter() int {
screen.inputField.SetID("filter") screen.inputField.SetID(InputIDFilter)
screen.inputField.SetX(len(screen.inputField.GetID()) + 2) return ScreenMain
} }
func (screen *MainScreen) setMessage(msg string) { func (screen *MainScreen) setMessage(msg string) {
@ -378,7 +487,7 @@ func (screen *MainScreen) setMessageWithTimeout(msg string, timeout time.Duratio
} }
func (screen *MainScreen) clearMessage() { func (screen *MainScreen) clearMessage() {
screen.message = "" screen.message = fmt.Sprintf("%d Total Tasks", len(screen.activeList))
screen.messageTimeout = -1 screen.messageTimeout = -1
} }

View File

@ -13,10 +13,10 @@ import (
// TaskScreen holds all that's going on // TaskScreen holds all that's going on
type TaskScreen struct { type TaskScreen struct {
viewPort *ViewPort
message string message string
messageTimeout time.Duration messageTimeout time.Duration
messageTime time.Time messageTime time.Time
cursor int
inputModal *termboxUtil.InputModal inputModal *termboxUtil.InputModal
confirmModal *termboxUtil.ConfirmModal confirmModal *termboxUtil.ConfirmModal
@ -31,7 +31,9 @@ const (
func (screen *TaskScreen) initialize(bundle Bundle) error { func (screen *TaskScreen) initialize(bundle Bundle) error {
var err error var err error
if bundle != nil {
screen.currentTaskId = bundle.getInt(TaskBundleTaskIdKey, -1) screen.currentTaskId = bundle.getInt(TaskBundleTaskIdKey, -1)
}
if screen.currentTaskId == -1 { if screen.currentTaskId == -1 {
return errors.New("Task Screen Initialization Failed") return errors.New("Task Screen Initialization Failed")
} }
@ -92,12 +94,12 @@ func (screen *TaskScreen) drawFooter() {
} }
func (screen *TaskScreen) moveCursorDown() bool { func (screen *TaskScreen) moveCursorDown() bool {
screen.viewPort.cursor++ screen.cursor++
return true return true
} }
func (screen *TaskScreen) moveCursorUp() bool { func (screen *TaskScreen) moveCursorUp() bool {
screen.viewPort.cursor-- screen.cursor--
return true return true
} }

View File

@ -47,6 +47,7 @@ func uiLoop() int {
} }
} }
if event.Type == termbox.EventResize { if event.Type == termbox.EventResize {
displayScreen.initialize(nil)
app.layoutAndDrawScreen(displayScreen) app.layoutAndDrawScreen(displayScreen)
} }
} }