Clean up behaviors

This commit is contained in:
Joscha 2018-09-29 11:21:51 +00:00
parent 55e12992b3
commit 3f88a247ce
3 changed files with 28 additions and 39 deletions

View file

@ -1,5 +1,6 @@
module TaskMachine.UI.Behaviors.TaskEdit
( taskEditBehavior
module TaskMachine.UI.Behaviors
( taskListBehavior
, taskEditBehavior
) where
import qualified Brick as B
@ -13,6 +14,14 @@ import TaskMachine.Task
import TaskMachine.UI.TaskList
import TaskMachine.UI.Types
startEdit :: UIState -> UIState
startEdit s =
case taskListSelectedElement (tasks s) of
Nothing -> undefined -- TODO: Add popup notification
Just t ->
let edit = B.editor RTaskEdit (Just 1) (formatTask t)
in s{taskEdit=Just edit}
finishEdit :: B.Editor String RName -> UIState -> UIState
finishEdit edit s =
let editedText = unlines $ B.getEditContents edit
@ -33,3 +42,15 @@ taskEditBehavior edit s (VTY.EvKey VTY.KEnter []) = do
taskEditBehavior edit s e = do
newEdit <- B.handleEditorEvent e edit
B.continue s{taskEdit=Just newEdit}
taskListBehavior :: UIState -> VTY.Event -> NewState
-- Mark/unmark a task as completed
taskListBehavior s (VTY.EvKey (VTY.KChar 'x') []) = undefined s
-- Delete tasks
taskListBehavior s (VTY.EvKey (VTY.KChar 'd') []) = undefined s
-- Start editing a new task
taskListBehavior s (VTY.EvKey (VTY.KChar 'e') []) = B.continue (startEdit s)
-- Update the task list (scroll etc.)
taskListBehavior s e = do
newTasks <- updateTaskList e (tasks s)
B.continue s{tasks=newTasks}

View file

@ -1,31 +0,0 @@
module TaskMachine.UI.Behaviors.TaskList
( taskListBehavior
) where
import qualified Brick as B
import qualified Brick.Widgets.Edit as B
import qualified Graphics.Vty as VTY
import TaskMachine.Task
import TaskMachine.UI.TaskList
import TaskMachine.UI.Types
startEdit :: UIState -> UIState
startEdit s =
case taskListSelectedElement (tasks s) of
Nothing -> undefined -- TODO: Add popup notification
Just t ->
let edit = B.editor RTaskEdit (Just 1) (formatTask t)
in s{taskEdit=Just edit}
taskListBehavior :: UIState -> VTY.Event -> NewState
-- Mark/unmark a task as completed
taskListBehavior s (VTY.EvKey (VTY.KChar 'x') []) = undefined s
-- Delete tasks
taskListBehavior s (VTY.EvKey (VTY.KChar 'd') []) = undefined s
-- Start editing a new task
taskListBehavior s (VTY.EvKey (VTY.KChar 'e') []) = B.continue (startEdit s)
-- Update the task list (scroll etc.)
taskListBehavior s e = do
newTasks <- updateTaskList e (tasks s)
B.continue s{tasks=newTasks}