dev:ui:refactor, clarify uiReload*
This commit is contained in:
parent
51842034dd
commit
27fcd50914
@ -231,7 +231,7 @@ asHandleNormalMode (ALS scons ass) ev = do
|
|||||||
-- XXX be sure we don't leave unconsumed app events piling up
|
-- XXX be sure we don't leave unconsumed app events piling up
|
||||||
-- A data file has changed (or the user has pressed g): reload.
|
-- A data file has changed (or the user has pressed g): reload.
|
||||||
e | e `elem` [AppEvent FileChange, VtyEvent (EvKey (KChar 'g') [])] ->
|
e | e `elem` [AppEvent FileChange, VtyEvent (EvKey (KChar 'g') [])] ->
|
||||||
liftIO (uiReload copts d ui) >>= put'
|
uiReload copts d ui >>= put'
|
||||||
|
|
||||||
-- The date has changed (and we are viewing a standard period which contained the old date):
|
-- The date has changed (and we are viewing a standard period which contained the old date):
|
||||||
-- adjust the viewed period and regenerate, just in case needed.
|
-- adjust the viewed period and regenerate, just in case needed.
|
||||||
|
|||||||
@ -94,7 +94,7 @@ esHandle ev = do
|
|||||||
Right (f',l,c) -> (Just (l, Just c),f')
|
Right (f',l,c) -> (Just (l, Just c),f')
|
||||||
Left _ -> (endPosition, journalFilePath j)
|
Left _ -> (endPosition, journalFilePath j)
|
||||||
e | e `elem` [VtyEvent (EvKey (KChar 'g') []), AppEvent FileChange] ->
|
e | e `elem` [VtyEvent (EvKey (KChar 'g') []), AppEvent FileChange] ->
|
||||||
liftIO (uiReload copts d (popScreen ui)) >>= put' . uiCheckBalanceAssertions d
|
uiReload copts d (popScreen ui) >>= put' . uiCheckBalanceAssertions d
|
||||||
-- (ej, _) <- liftIO $ journalReloadIfChanged copts d j
|
-- (ej, _) <- liftIO $ journalReloadIfChanged copts d j
|
||||||
-- case ej of
|
-- case ej of
|
||||||
-- Left err -> continue ui{aScreen=s{esError=err}} -- show latest parse error
|
-- Left err -> continue ui{aScreen=s{esError=err}} -- show latest parse error
|
||||||
@ -142,8 +142,8 @@ hledgerparseerrorpositionp = do
|
|||||||
-- Like at hledger-ui startup, --forecast is always enabled.
|
-- Like at hledger-ui startup, --forecast is always enabled.
|
||||||
-- A forecast period specified in the provided opts, or at startup, is preserved.
|
-- A forecast period specified in the provided opts, or at startup, is preserved.
|
||||||
--
|
--
|
||||||
uiReload :: CliOpts -> Day -> UIState -> IO UIState
|
uiReload :: CliOpts -> Day -> UIState -> EventM Name UIState UIState
|
||||||
uiReload copts d ui = do
|
uiReload copts d ui = liftIO $ do
|
||||||
ej <-
|
ej <-
|
||||||
let copts' = enableForecast (astartupopts ui) copts
|
let copts' = enableForecast (astartupopts ui) copts
|
||||||
in runExceptT $ journalTransform copts' <$> journalReload copts'
|
in runExceptT $ journalTransform copts' <$> journalReload copts'
|
||||||
@ -165,9 +165,9 @@ uiReload copts d ui = do
|
|||||||
-- RegisterScreen _ _ _ _ _ _
|
-- RegisterScreen _ _ _ _ _ _
|
||||||
-- TransactionScreen _ _ _ _ _ _
|
-- TransactionScreen _ _ _ _ _ _
|
||||||
|
|
||||||
-- | Like uiReload, but does not re-parse the journal if the file(s)
|
-- | Like uiReload, except it skips re-reading the journal if its file(s) have not changed
|
||||||
-- have not changed since last loaded. Always regenerates the screens though,
|
-- since it was last loaded. The up app state is always updated, since the options or today-date may have changed.
|
||||||
-- since the provided options or today-date may have changed.
|
-- Also, this one runs in IO, suitable for suspendAndResume.
|
||||||
uiReloadIfFileChanged :: CliOpts -> Day -> Journal -> UIState -> IO UIState
|
uiReloadIfFileChanged :: CliOpts -> Day -> Journal -> UIState -> IO UIState
|
||||||
uiReloadIfFileChanged copts d j ui = do
|
uiReloadIfFileChanged copts d j ui = do
|
||||||
let copts' = enableForecast (astartupopts ui) copts
|
let copts' = enableForecast (astartupopts ui) copts
|
||||||
|
|||||||
@ -155,8 +155,7 @@ msHandle ev = do
|
|||||||
put' $ regenerateScreens j d $ setReportPeriod (DayPeriod d) ui
|
put' $ regenerateScreens j d $ setReportPeriod (DayPeriod d) ui
|
||||||
where
|
where
|
||||||
p = reportPeriod ui
|
p = reportPeriod ui
|
||||||
e | e `elem` [VtyEvent (EvKey (KChar 'g') []), AppEvent FileChange] ->
|
e | e `elem` [VtyEvent (EvKey (KChar 'g') []), AppEvent FileChange] -> uiReload copts d ui >>= put'
|
||||||
liftIO (uiReload copts d ui) >>= put'
|
|
||||||
VtyEvent (EvKey (KChar 'I') []) -> put' $ uiCheckBalanceAssertions d (toggleIgnoreBalanceAssertions ui)
|
VtyEvent (EvKey (KChar 'I') []) -> put' $ uiCheckBalanceAssertions d (toggleIgnoreBalanceAssertions ui)
|
||||||
VtyEvent (EvKey (KChar 'a') []) -> suspendAndResume $ clearScreen >> setCursorPosition 0 0 >> add (cliOptsDropArgs copts) j >> uiReloadIfFileChanged copts d j ui
|
VtyEvent (EvKey (KChar 'a') []) -> suspendAndResume $ clearScreen >> setCursorPosition 0 0 >> add (cliOptsDropArgs copts) j >> uiReloadIfFileChanged copts d j ui
|
||||||
VtyEvent (EvKey (KChar 'A') []) -> suspendAndResume $ void (runIadd (journalFilePath j)) >> uiReloadIfFileChanged copts d j ui
|
VtyEvent (EvKey (KChar 'A') []) -> suspendAndResume $ void (runIadd (journalFilePath j)) >> uiReloadIfFileChanged copts d j ui
|
||||||
|
|||||||
@ -245,8 +245,7 @@ rsHandle ev = do
|
|||||||
where
|
where
|
||||||
p = reportPeriod ui
|
p = reportPeriod ui
|
||||||
|
|
||||||
e | e `elem` [AppEvent FileChange, VtyEvent (EvKey (KChar 'g') [])] ->
|
e | e `elem` [AppEvent FileChange, VtyEvent (EvKey (KChar 'g') [])] -> uiReload copts d ui >>= put'
|
||||||
liftIO (uiReload copts d ui) >>= put'
|
|
||||||
|
|
||||||
VtyEvent (EvKey (KChar 'I') []) -> put' $ uiCheckBalanceAssertions d (toggleIgnoreBalanceAssertions ui)
|
VtyEvent (EvKey (KChar 'I') []) -> put' $ uiCheckBalanceAssertions d (toggleIgnoreBalanceAssertions ui)
|
||||||
VtyEvent (EvKey (KChar 'a') []) -> suspendAndResume $ clearScreen >> setCursorPosition 0 0 >> add (cliOptsDropArgs copts) j >> uiReloadIfFileChanged copts d j ui
|
VtyEvent (EvKey (KChar 'a') []) -> suspendAndResume $ clearScreen >> setCursorPosition 0 0 >> add (cliOptsDropArgs copts) j >> uiReloadIfFileChanged copts d j ui
|
||||||
|
|||||||
@ -144,7 +144,7 @@ tsHandle ev = do
|
|||||||
e | e `elem` [VtyEvent (EvKey (KChar 'g') []), AppEvent FileChange] -> do
|
e | e `elem` [VtyEvent (EvKey (KChar 'g') []), AppEvent FileChange] -> do
|
||||||
-- To update all state: exit to register screen, regenerate screens, re-enter transaction screen.
|
-- To update all state: exit to register screen, regenerate screens, re-enter transaction screen.
|
||||||
-- Anywhere else here that we need to be this thorough ?
|
-- Anywhere else here that we need to be this thorough ?
|
||||||
put' =<< liftIO (popScreen ui & uiReload copts d)
|
uiReload copts d (popScreen ui) >>= put'
|
||||||
rsHandle (VtyEvent (EvKey KEnter []))
|
rsHandle (VtyEvent (EvKey KEnter []))
|
||||||
--
|
--
|
||||||
-- for debugging; leaving these here because they were hard to find
|
-- for debugging; leaving these here because they were hard to find
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user