diff --git a/hledger-ui/Hledger/UI/AccountsScreen.hs b/hledger-ui/Hledger/UI/AccountsScreen.hs index 267e7b63c..4c5052914 100644 --- a/hledger-ui/Hledger/UI/AccountsScreen.hs +++ b/hledger-ui/Hledger/UI/AccountsScreen.hs @@ -48,7 +48,7 @@ import Hledger.UI.UIState import Hledger.UI.UIUtils import Hledger.UI.UIScreens import Hledger.UI.Editor -import Hledger.UI.ErrorScreen (uiReloadJournal, uiCheckBalanceAssertions, uiReloadJournalIfChanged) +import Hledger.UI.ErrorScreen (uiCheckBalanceAssertions, uiReload, uiReloadIfFileChanged) import Hledger.UI.RegisterScreen (rsCenterSelection) import Data.Either (fromRight) import Control.Arrow ((>>>)) @@ -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 (uiReloadJournal copts d ui) >>= put' + liftIO (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. @@ -245,9 +245,9 @@ asHandleNormalMode (ALS scons ass) ev = do VtyEvent (EvKey k []) | k `elem` [KBS, KDel] -> modify' (resetFilter >>> regenerateScreens j d) -- run external programs: - VtyEvent (EvKey (KChar 'a') []) -> suspendAndResume $ clearScreen >> setCursorPosition 0 0 >> add (cliOptsDropArgs copts) j >> uiReloadJournalIfChanged copts d j ui - VtyEvent (EvKey (KChar 'A') []) -> suspendAndResume $ void (runIadd (journalFilePath j)) >> uiReloadJournalIfChanged copts d j ui - VtyEvent (EvKey (KChar 'E') []) -> suspendAndResume $ void (runEditor endPosition (journalFilePath j)) >> uiReloadJournalIfChanged 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 'E') []) -> suspendAndResume $ void (runEditor endPosition (journalFilePath j)) >> uiReloadIfFileChanged copts d j ui -- adjust the period displayed: VtyEvent (EvKey (KChar 'T') []) -> modify' (setReportPeriod (DayPeriod d) >>> regenerateScreens j d) diff --git a/hledger-ui/Hledger/UI/ErrorScreen.hs b/hledger-ui/Hledger/UI/ErrorScreen.hs index f244b2725..e6954688c 100644 --- a/hledger-ui/Hledger/UI/ErrorScreen.hs +++ b/hledger-ui/Hledger/UI/ErrorScreen.hs @@ -11,8 +11,8 @@ module Hledger.UI.ErrorScreen ,esDraw ,esHandle ,uiCheckBalanceAssertions - ,uiReloadJournal - ,uiReloadJournalIfChanged + ,uiReload + ,uiReloadIfFileChanged ) where @@ -88,13 +88,13 @@ esHandle ev = do VtyEvent (EvKey (KChar 'q') []) -> halt VtyEvent (EvKey KEsc []) -> put' $ uiCheckBalanceAssertions d $ resetScreens d ui VtyEvent (EvKey (KChar c) []) | c `elem` ['h','?'] -> put' $ setMode Help ui - VtyEvent (EvKey (KChar 'E') []) -> suspendAndResume $ void (runEditor pos f) >> uiReloadJournalIfChanged copts d j (popScreen ui) + VtyEvent (EvKey (KChar 'E') []) -> suspendAndResume $ void (runEditor pos f) >> uiReloadIfFileChanged copts d j (popScreen ui) where (pos,f) = case parsewithString hledgerparseerrorpositionp _essError of Right (f',l,c) -> (Just (l, Just c),f') Left _ -> (endPosition, journalFilePath j) e | e `elem` [VtyEvent (EvKey (KChar 'g') []), AppEvent FileChange] -> - liftIO (uiReloadJournal copts d (popScreen ui)) >>= put' . uiCheckBalanceAssertions d + liftIO (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 @@ -130,29 +130,27 @@ hledgerparseerrorpositionp = do ] --- | Unconditionally reload the journal, regenerating the current screen --- and all previous screens in the history as of the provided today-date. --- If reloading fails, enter the error screen, or if we're already --- on the error screen, update the error displayed. --- Defined here so it can reference the error screen. +-- Defined here so it can reference the error screen: + +-- | Reload the journal from its input files, then update the ui app state accordingly. +-- This means regenerate the entire screen stack from top level down to the current screen, using the provided today-date. +-- Or if journal reloading fails, enter the error screen; or if already there, update its message. -- --- The provided CliOpts are used for reloading, and then saved in the --- UIState if reloading is successful (otherwise the UIState keeps its old --- CliOpts.) (XXX needed for.. ?) +-- The provided cli options can influence reloading; then if reloading succeeds they are saved in the ui state, +-- otherwise the UIState keeps its old options. (XXX needed for.. ?) -- --- Forecasted transactions are always generated, as at hledger-ui startup. --- If a forecast period is specified in the provided opts, or was specified --- at startup, it is preserved. +-- Like at hledger-ui startup, --forecast is always enabled. +-- A forecast period specified in the provided opts, or at startup, is preserved. -- -uiReloadJournal :: CliOpts -> Day -> UIState -> IO UIState -uiReloadJournal copts d ui = do +uiReload :: CliOpts -> Day -> UIState -> IO UIState +uiReload copts d ui = do ej <- let copts' = enableForecastPreservingPeriod ui copts in runExceptT $ journalTransform copts' <$> journalReload copts' - -- dbg1IO "uiReloadJournal before reload" (map tdescription $ jtxns $ ajournal ui) + -- dbg1IO "uiReload before reload" (map tdescription $ jtxns $ ajournal ui) return $ case ej of Right j -> - -- dbg1 "uiReloadJournal after reload" (map tdescription $ jtxns j) $ + -- dbg1 "uiReload after reload" (map tdescription $ jtxns j) $ regenerateScreens j d ui Left err -> case ui of @@ -167,11 +165,11 @@ uiReloadJournal copts d ui = do -- RegisterScreen _ _ _ _ _ _ -- TransactionScreen _ _ _ _ _ _ --- | Like uiReloadJournal, but does not re-parse the journal if the file(s) +-- | 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. -uiReloadJournalIfChanged :: CliOpts -> Day -> Journal -> UIState -> IO UIState -uiReloadJournalIfChanged copts d j ui = do +uiReloadIfFileChanged :: CliOpts -> Day -> Journal -> UIState -> IO UIState +uiReloadIfFileChanged copts d j ui = do let copts' = enableForecastPreservingPeriod ui copts ej <- runExceptT $ journalReloadIfChanged copts' d j return $ case ej of diff --git a/hledger-ui/Hledger/UI/MenuScreen.hs b/hledger-ui/Hledger/UI/MenuScreen.hs index 61ed6fe1c..ebab451de 100644 --- a/hledger-ui/Hledger/UI/MenuScreen.hs +++ b/hledger-ui/Hledger/UI/MenuScreen.hs @@ -33,7 +33,7 @@ import Hledger.UI.UITypes import Hledger.UI.UIState import Hledger.UI.UIUtils import Hledger.UI.UIScreens -import Hledger.UI.ErrorScreen (uiReloadJournal, uiCheckBalanceAssertions, uiReloadJournalIfChanged) +import Hledger.UI.ErrorScreen (uiCheckBalanceAssertions, uiReload, uiReloadIfFileChanged) import Hledger.UI.Editor (runIadd, runEditor, endPosition) import Brick.Widgets.Edit (getEditContents, handleEditorEvent) import Control.Arrow ((>>>)) @@ -156,11 +156,11 @@ msHandle ev = do where p = reportPeriod ui e | e `elem` [VtyEvent (EvKey (KChar 'g') []), AppEvent FileChange] -> - liftIO (uiReloadJournal copts d ui) >>= put' + liftIO (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 >> uiReloadJournalIfChanged copts d j ui - VtyEvent (EvKey (KChar 'A') []) -> suspendAndResume $ void (runIadd (journalFilePath j)) >> uiReloadJournalIfChanged copts d j ui - VtyEvent (EvKey (KChar 'E') []) -> suspendAndResume $ void (runEditor endPosition (journalFilePath j)) >> uiReloadJournalIfChanged 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 'E') []) -> suspendAndResume $ void (runEditor endPosition (journalFilePath j)) >> uiReloadIfFileChanged copts d j ui -- VtyEvent (EvKey (KChar 'B') []) -> put' $ regenerateScreens j d $ toggleConversionOp ui -- VtyEvent (EvKey (KChar 'V') []) -> put' $ regenerateScreens j d $ toggleValue ui diff --git a/hledger-ui/Hledger/UI/RegisterScreen.hs b/hledger-ui/Hledger/UI/RegisterScreen.hs index a736f12cc..2afd82dff 100644 --- a/hledger-ui/Hledger/UI/RegisterScreen.hs +++ b/hledger-ui/Hledger/UI/RegisterScreen.hs @@ -43,7 +43,7 @@ import Hledger.UI.UIState import Hledger.UI.UIUtils import Hledger.UI.UIScreens import Hledger.UI.Editor -import Hledger.UI.ErrorScreen (uiReloadJournal, uiCheckBalanceAssertions, uiReloadJournalIfChanged) +import Hledger.UI.ErrorScreen (uiCheckBalanceAssertions, uiReload, uiReloadIfFileChanged) rsDraw :: UIState -> [Widget Name] rsDraw UIState{aopts=_uopts@UIOpts{uoCliOpts=copts@CliOpts{reportspec_=rspec}} @@ -246,13 +246,13 @@ rsHandle ev = do p = reportPeriod ui e | e `elem` [AppEvent FileChange, VtyEvent (EvKey (KChar 'g') [])] -> - liftIO (uiReloadJournal copts d ui) >>= put' + liftIO (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 >> uiReloadJournalIfChanged copts d j ui - VtyEvent (EvKey (KChar 'A') []) -> suspendAndResume $ void (runIadd (journalFilePath j)) >> uiReloadJournalIfChanged 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 'T') []) -> put' $ regenerateScreens j d $ setReportPeriod (DayPeriod d) ui - VtyEvent (EvKey (KChar 'E') []) -> suspendAndResume $ void (runEditor pos f) >> uiReloadJournalIfChanged copts d j ui + VtyEvent (EvKey (KChar 'E') []) -> suspendAndResume $ void (runEditor pos f) >> uiReloadIfFileChanged copts d j ui where (pos,f) = case listSelectedElement _rssList of Nothing -> (endPosition, journalFilePath j) diff --git a/hledger-ui/Hledger/UI/TransactionScreen.hs b/hledger-ui/Hledger/UI/TransactionScreen.hs index e01da60aa..cad3ae752 100644 --- a/hledger-ui/Hledger/UI/TransactionScreen.hs +++ b/hledger-ui/Hledger/UI/TransactionScreen.hs @@ -29,7 +29,7 @@ import Hledger.UI.UIState import Hledger.UI.UIUtils import Hledger.UI.UIScreens import Hledger.UI.Editor -import Hledger.UI.ErrorScreen (uiReloadJournalIfChanged, uiCheckBalanceAssertions, uiReloadJournal) +import Hledger.UI.ErrorScreen (uiCheckBalanceAssertions, uiReload, uiReloadIfFileChanged) import Hledger.UI.RegisterScreen (rsHandle) import System.Exit (ExitCode(..)) import Data.Function ((&)) @@ -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 & uiReloadJournal copts d) + put' =<< liftIO (popScreen ui & uiReload copts d) rsHandle (VtyEvent (EvKey KEnter [])) -- -- for debugging; leaving these here because they were hard to find @@ -158,8 +158,8 @@ tsHandle ev = do case exitcode of ExitSuccess -> return () ExitFailure c -> error' $ "running the text editor failed with exit code " ++ show c - -- Like above: exit to register screen, regenerate screens (if file has changed), re-enter transaction screen. - put' =<< liftIO (popScreen ui & uiReloadJournalIfChanged copts d j) + -- Update all state, similar to above. + put' =<< liftIO (popScreen ui & uiReloadIfFileChanged copts d j) rsHandle (VtyEvent (EvKey KEnter [])) where (pos,f) = case tsourcepos t of (SourcePos f' l1 c1,_) -> (Just (unPos l1, Just $ unPos c1),f') diff --git a/hledger/Hledger/Cli/Utils.hs b/hledger/Hledger/Cli/Utils.hs index 47f543e37..5ffcf441a 100644 --- a/hledger/Hledger/Cli/Utils.hs +++ b/hledger/Hledger/Cli/Utils.hs @@ -84,7 +84,7 @@ withJournalDo = withJournal -- --pivot, --anonymise error message, --obfuscate. journalTransform :: CliOpts -> Journal -> Journal journalTransform opts = --- XXX Called by withJournal, journalReload, uiReloadJournal, withJournalCached. +-- XXX Called by withJournal, journalReload, uiReload, withJournalCached. -- Could it be moved down into journalFinalise ? These steps only depend on InputOpts. maybePivot opts <&> maybeWarnAboutAnon opts