Move task list related controls to new behavior
This commit is contained in:
parent
11ef930835
commit
7fb6ff4add
5 changed files with 44 additions and 27 deletions
|
|
@ -13,6 +13,7 @@ import qualified Graphics.Vty.Input.Events as VTY
|
|||
import TaskMachine.LTask
|
||||
import TaskMachine.Options
|
||||
import TaskMachine.UI.Behaviors.TaskEdit
|
||||
import TaskMachine.UI.Behaviors.TaskList
|
||||
import TaskMachine.UI.Popup
|
||||
import TaskMachine.UI.TaskList
|
||||
import TaskMachine.UI.Types
|
||||
|
|
@ -61,18 +62,6 @@ focusBehavior _ s (VTY.EvKey (VTY.KChar '\t') []) = B.continue $ bigFocusNext s
|
|||
focusBehavior _ s (VTY.EvKey VTY.KBackTab []) = B.continue $ bigFocusPrev s
|
||||
focusBehavior f s e = f s e -- wrapper around another behavior
|
||||
|
||||
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}
|
||||
|
||||
selectBehavior :: UIState -> VTY.Event -> NewState
|
||||
-- Deal with popup if there is one
|
||||
selectBehavior s@UIState{errorPopup=Just popup} e = undefined popup s e
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
module TaskMachine.UI.Behaviors.TaskEdit
|
||||
( startEdit
|
||||
, taskEditBehavior
|
||||
( taskEditBehavior
|
||||
) where
|
||||
|
||||
import qualified Brick as B
|
||||
|
|
@ -13,14 +12,6 @@ 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
|
||||
|
|
@ -34,10 +25,10 @@ taskEditBehavior :: B.Editor String RName -> UIState -> VTY.Event -> NewState
|
|||
taskEditBehavior _ s (VTY.EvKey VTY.KEsc []) = B.continue s{taskEdit=Nothing}
|
||||
taskEditBehavior edit s (VTY.EvKey VTY.KHome []) = B.continue s{taskEdit=Just (B.applyEdit T.gotoBOL edit)}
|
||||
taskEditBehavior edit s (VTY.EvKey VTY.KEnd []) = B.continue s{taskEdit=Just (B.applyEdit T.gotoEOL edit)}
|
||||
taskEditBehavior edit s (VTY.EvKey VTY.KEnter []) = do
|
||||
taskEditBehavior edit s (VTY.EvKey VTY.KEnter []) = B.suspendAndResume $ do
|
||||
let newState = finishEdit edit s
|
||||
-- TODO: Save changes to file
|
||||
B.continue newState
|
||||
saveUIState newState
|
||||
pure newState
|
||||
taskEditBehavior edit s e = do
|
||||
newEdit <- B.handleEditorEvent e edit
|
||||
B.continue s{taskEdit=Just newEdit}
|
||||
|
|
|
|||
31
src/TaskMachine/UI/Behaviors/TaskList.hs
Normal file
31
src/TaskMachine/UI/Behaviors/TaskList.hs
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
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}
|
||||
|
|
@ -19,6 +19,7 @@ module TaskMachine.UI.Types
|
|||
, bigFocusNext, bigFocusPrev
|
||||
--, smallFocusNext, smallFocusPrev
|
||||
, defaultTheme
|
||||
, saveUIState
|
||||
) where
|
||||
|
||||
import qualified Brick as B
|
||||
|
|
@ -30,7 +31,7 @@ import qualified Brick.Widgets.List as B
|
|||
import qualified Graphics.Vty as VTY
|
||||
--import qualified Data.Vector as V
|
||||
|
||||
--import TaskMachine.LTask
|
||||
import TaskMachine.LTask
|
||||
import TaskMachine.Options
|
||||
import TaskMachine.UI.Popup
|
||||
import TaskMachine.UI.Task
|
||||
|
|
@ -180,3 +181,9 @@ defaultTheme = B.newTheme VTY.defAttr
|
|||
bg' = VTY.withBackColor none
|
||||
st' = VTY.withStyle none
|
||||
none = VTY.defAttr
|
||||
|
||||
saveUIState :: UIState -> IO ()
|
||||
saveUIState s = do
|
||||
let filepath = oTodofile (options s)
|
||||
ltasks = taskListElements (tasks s)
|
||||
saveLTasks filepath ltasks
|
||||
|
|
|
|||
1
todo.txt
1
todo.txt
|
|
@ -4,7 +4,6 @@
|
|||
- c2018-09-18 Offer to clean up file when loading (adding creation/completion dates)
|
||||
- c2018-09-18 Purge - move completed tasks to a separate file
|
||||
- c2018-09-18 Sort tasks by completion, priority, due date, description
|
||||
- c2018-09-28 Load file in initial app action
|
||||
- c2018-09-28 Move cursor to beginning of task description when editing tasks
|
||||
- c2018-09-28 Syntax highlighting while editing tasks
|
||||
x2018-09-27 c2018-09-18 Quit using Esc or q
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue