Clean up old stuff
This commit is contained in:
parent
efeeef39eb
commit
55e12992b3
4 changed files with 27 additions and 355 deletions
|
|
@ -5,103 +5,44 @@ module TaskMachine.UI
|
|||
) where
|
||||
|
||||
import qualified Brick as B
|
||||
import qualified Brick.Focus as B
|
||||
import qualified Brick.Themes as B
|
||||
import qualified Data.Vector as V
|
||||
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
|
||||
|
||||
{- Rendering -}
|
||||
|
||||
placeholderTopBar :: B.Widget n
|
||||
placeholderTopBar = B.str "Prune | Reload | Search: " B.<+> B.vLimit 1 (B.fill '_')
|
||||
|
||||
placeholderNewTask :: B.Widget RName
|
||||
placeholderNewTask = B.str "New: " B.<+> B.vLimit 1 (B.fill '_')
|
||||
|
||||
drawTaskList :: Bool -> UIState -> B.Widget RName
|
||||
drawTaskList focused s = renderTaskList (taskEdit s) focused (tasks s)
|
||||
|
||||
drawBaseLayer :: UIState -> B.Widget RName
|
||||
drawBaseLayer s = B.vBox [placeholderTopBar, drawTaskList True s, placeholderNewTask]
|
||||
drawTaskList :: UIState -> B.Widget RName
|
||||
drawTaskList s = renderTaskList (taskEdit s) True (tasks s)
|
||||
|
||||
drawUIState :: UIState -> [B.Widget RName]
|
||||
drawUIState s@UIState{errorPopup=Just p} = [renderPopupOk p, drawBaseLayer s]
|
||||
drawUIState s = [drawBaseLayer s]
|
||||
|
||||
{- Actions -}
|
||||
|
||||
loadTasks :: UIState -> IO UIState
|
||||
loadTasks s = do
|
||||
let file = oTodofile $ options s
|
||||
result <- loadLTasks file
|
||||
case result of
|
||||
-- TODO: Improve error handling when loading files
|
||||
Left errorMessage -> pure s{errorPopup=Just $ popupOk "Error loading tasks" errorMessage}
|
||||
Right ltasks -> pure s{tasks=taskList RTaskList ltasks}
|
||||
--drawUIState s@UIState{errorPopup=Just p} = [renderPopupOk p, drawTaskList s]
|
||||
drawUIState s = [drawTaskList s]
|
||||
|
||||
{- Updating the state -}
|
||||
|
||||
rootBehavior :: UIState -> VTY.Event -> NewState
|
||||
rootBehavior s _ = B.continue s
|
||||
|
||||
closeBehavior :: (UIState -> VTY.Event -> NewState) -> UIState -> VTY.Event -> NewState
|
||||
closeBehavior _ s (VTY.EvKey VTY.KEsc []) = B.halt s
|
||||
closeBehavior _ s (VTY.EvKey (VTY.KChar 'q') []) = B.halt s
|
||||
closeBehavior f s e = f s e -- wrapper around another behavior
|
||||
|
||||
focusBehavior :: (UIState -> VTY.Event -> NewState) -> UIState -> VTY.Event -> NewState
|
||||
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
|
||||
|
||||
selectBehavior :: UIState -> VTY.Event -> NewState
|
||||
-- Deal with popup if there is one
|
||||
selectBehavior s@UIState{errorPopup=Just popup} e = undefined popup s e
|
||||
--selectBehavior s@UIState{errorPopup=Just popup} e = undefined popup s e
|
||||
-- Under the assumption that tasks can only be edited while the task list is focused, edit a task
|
||||
selectBehavior s@UIState{taskEdit=Just edit} e = taskEditBehavior edit s e
|
||||
-- If nothing immediately jumps out at you, see which part has focus.
|
||||
selectBehavior s e =
|
||||
case B.focusGetCurrent (focus s) of
|
||||
Just BRTopBar -> closeBehavior (focusBehavior rootBehavior) s e
|
||||
Just BRTaskList -> closeBehavior (focusBehavior taskListBehavior) s e
|
||||
Just BRNewTask -> closeBehavior (focusBehavior rootBehavior) s e
|
||||
Nothing -> closeBehavior (focusBehavior rootBehavior) s e
|
||||
selectBehavior s e = closeBehavior taskListBehavior s e
|
||||
|
||||
updateUIState :: UIState -> B.BrickEvent RName () -> NewState
|
||||
updateUIState s (B.VtyEvent e) = selectBehavior s e
|
||||
updateUIState s _ = B.continue s
|
||||
|
||||
{-
|
||||
updateUIState :: UIState -> B.BrickEvent RName () -> B.EventM RName (B.Next UIState)
|
||||
-- Closing error popup
|
||||
updateUIState s@UIState{errorPopup=Just _} (B.VtyEvent (VTY.EvKey VTY.KEnter [])) = B.continue s{errorPopup=Nothing}
|
||||
updateUIState s@UIState{errorPopup=Just _} (B.VtyEvent (VTY.EvKey VTY.KEsc [])) = B.continue s{errorPopup=Nothing}
|
||||
--updateUIState s@UIState{errorPopup=Just p} (B.VtyEvent e) = do
|
||||
-- newPopup <- handlePopupEvent e p
|
||||
-- B.continue s{errorPopup=Just newPopup}
|
||||
updateUIState s e =
|
||||
case B.focusGetCurrent (focus s) of
|
||||
Nothing -> B.halt s
|
||||
(Just BRTopBar) -> placeholderUpdate s e
|
||||
--(Just BRTaskList) -> updateTaskList s e
|
||||
(Just BRTaskList) -> placeholderUpdate s e
|
||||
(Just BRNewTask) -> placeholderUpdate s e
|
||||
|
||||
placeholderUpdate :: UIState -> B.BrickEvent RName () -> B.EventM RName (B.Next UIState)
|
||||
placeholderUpdate s (B.VtyEvent (VTY.EvKey VTY.KEsc [])) = B.halt s
|
||||
placeholderUpdate s (B.VtyEvent (VTY.EvKey (VTY.KChar '\t') [])) = B.continue $ bigFocusNext s
|
||||
placeholderUpdate s (B.VtyEvent (VTY.EvKey VTY.KBackTab [])) = B.continue $ bigFocusPrev s
|
||||
placeholderUpdate s _ = B.continue s
|
||||
-}
|
||||
|
||||
{- Starting the app -}
|
||||
|
||||
myApp :: B.App UIState () RName
|
||||
|
|
@ -116,8 +57,7 @@ myApp = B.App
|
|||
startUIState :: Options -> UIState
|
||||
startUIState o = UIState
|
||||
{ options = o
|
||||
, focus = B.focusRing [BRTaskList, BRNewTask, BRTopBar]
|
||||
, errorPopup = Nothing
|
||||
--, errorPopup = Nothing
|
||||
, tasks = taskList RTaskList V.empty
|
||||
, taskEdit = Nothing
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue