dev:ui:refactor, clarify uiReload*

This commit is contained in:
Simon Michael 2025-09-11 23:59:34 +01:00
parent 51842034dd
commit 27fcd50914
5 changed files with 10 additions and 12 deletions

View File

@ -231,7 +231,7 @@ asHandleNormalMode (ALS scons ass) ev = do
-- XXX be sure we don't leave unconsumed app events piling up
-- A data file has changed (or the user has pressed g): reload.
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):
-- adjust the viewed period and regenerate, just in case needed.

View File

@ -94,7 +94,7 @@ esHandle ev = do
Right (f',l,c) -> (Just (l, Just c),f')
Left _ -> (endPosition, journalFilePath j)
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
-- case ej of
-- 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.
-- A forecast period specified in the provided opts, or at startup, is preserved.
--
uiReload :: CliOpts -> Day -> UIState -> IO UIState
uiReload copts d ui = do
uiReload :: CliOpts -> Day -> UIState -> EventM Name UIState UIState
uiReload copts d ui = liftIO $ do
ej <-
let copts' = enableForecast (astartupopts ui) copts
in runExceptT $ journalTransform copts' <$> journalReload copts'
@ -165,9 +165,9 @@ uiReload copts d ui = do
-- RegisterScreen _ _ _ _ _ _
-- TransactionScreen _ _ _ _ _ _
-- | Like uiReload, but does not re-parse the journal if the file(s)
-- have not changed since last loaded. Always regenerates the screens though,
-- since the provided options or today-date may have changed.
-- | Like uiReload, except it skips re-reading the journal if its file(s) have not changed
-- since it was last loaded. The up app state is always updated, since the options or today-date may have changed.
-- Also, this one runs in IO, suitable for suspendAndResume.
uiReloadIfFileChanged :: CliOpts -> Day -> Journal -> UIState -> IO UIState
uiReloadIfFileChanged copts d j ui = do
let copts' = enableForecast (astartupopts ui) copts

View File

@ -155,8 +155,7 @@ msHandle ev = do
put' $ regenerateScreens j d $ setReportPeriod (DayPeriod d) ui
where
p = reportPeriod ui
e | e `elem` [VtyEvent (EvKey (KChar 'g') []), AppEvent FileChange] ->
liftIO (uiReload copts d ui) >>= put'
e | e `elem` [VtyEvent (EvKey (KChar 'g') []), AppEvent FileChange] -> uiReload copts d ui >>= put'
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 $ void (runIadd (journalFilePath j)) >> uiReloadIfFileChanged copts d j ui

View File

@ -245,8 +245,7 @@ rsHandle ev = do
where
p = reportPeriod ui
e | e `elem` [AppEvent FileChange, VtyEvent (EvKey (KChar 'g') [])] ->
liftIO (uiReload copts d ui) >>= put'
e | e `elem` [AppEvent FileChange, VtyEvent (EvKey (KChar 'g') [])] -> uiReload copts d ui >>= put'
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

View File

@ -144,7 +144,7 @@ tsHandle ev = 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.
-- 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 []))
--
-- for debugging; leaving these here because they were hard to find