lib:Hledger.UI.ErrorScreen: rename, clarify uiReload*
uiReloadJournal -> uiReload uiReloadJournalIfChanged -> uiReloadIfFileChanged
This commit is contained in:
parent
c7c196caa6
commit
7ccc0d5bdd
@ -48,7 +48,7 @@ import Hledger.UI.UIState
|
|||||||
import Hledger.UI.UIUtils
|
import Hledger.UI.UIUtils
|
||||||
import Hledger.UI.UIScreens
|
import Hledger.UI.UIScreens
|
||||||
import Hledger.UI.Editor
|
import Hledger.UI.Editor
|
||||||
import Hledger.UI.ErrorScreen (uiReloadJournal, uiCheckBalanceAssertions, uiReloadJournalIfChanged)
|
import Hledger.UI.ErrorScreen (uiCheckBalanceAssertions, uiReload, uiReloadIfFileChanged)
|
||||||
import Hledger.UI.RegisterScreen (rsCenterSelection)
|
import Hledger.UI.RegisterScreen (rsCenterSelection)
|
||||||
import Data.Either (fromRight)
|
import Data.Either (fromRight)
|
||||||
import Control.Arrow ((>>>))
|
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
|
-- 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 (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):
|
-- 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.
|
||||||
@ -245,9 +245,9 @@ asHandleNormalMode (ALS scons ass) ev = do
|
|||||||
VtyEvent (EvKey k []) | k `elem` [KBS, KDel] -> modify' (resetFilter >>> regenerateScreens j d)
|
VtyEvent (EvKey k []) | k `elem` [KBS, KDel] -> modify' (resetFilter >>> regenerateScreens j d)
|
||||||
|
|
||||||
-- run external programs:
|
-- 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 $ clearScreen >> setCursorPosition 0 0 >> add (cliOptsDropArgs copts) j >> uiReloadIfFileChanged copts d j ui
|
||||||
VtyEvent (EvKey (KChar 'A') []) -> suspendAndResume $ void (runIadd (journalFilePath j)) >> uiReloadJournalIfChanged 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)) >> uiReloadJournalIfChanged copts d j ui
|
VtyEvent (EvKey (KChar 'E') []) -> suspendAndResume $ void (runEditor endPosition (journalFilePath j)) >> uiReloadIfFileChanged copts d j ui
|
||||||
|
|
||||||
-- adjust the period displayed:
|
-- adjust the period displayed:
|
||||||
VtyEvent (EvKey (KChar 'T') []) -> modify' (setReportPeriod (DayPeriod d) >>> regenerateScreens j d)
|
VtyEvent (EvKey (KChar 'T') []) -> modify' (setReportPeriod (DayPeriod d) >>> regenerateScreens j d)
|
||||||
|
|||||||
@ -11,8 +11,8 @@ module Hledger.UI.ErrorScreen
|
|||||||
,esDraw
|
,esDraw
|
||||||
,esHandle
|
,esHandle
|
||||||
,uiCheckBalanceAssertions
|
,uiCheckBalanceAssertions
|
||||||
,uiReloadJournal
|
,uiReload
|
||||||
,uiReloadJournalIfChanged
|
,uiReloadIfFileChanged
|
||||||
)
|
)
|
||||||
where
|
where
|
||||||
|
|
||||||
@ -88,13 +88,13 @@ esHandle ev = do
|
|||||||
VtyEvent (EvKey (KChar 'q') []) -> halt
|
VtyEvent (EvKey (KChar 'q') []) -> halt
|
||||||
VtyEvent (EvKey KEsc []) -> put' $ uiCheckBalanceAssertions d $ resetScreens d ui
|
VtyEvent (EvKey KEsc []) -> put' $ uiCheckBalanceAssertions d $ resetScreens d ui
|
||||||
VtyEvent (EvKey (KChar c) []) | c `elem` ['h','?'] -> put' $ setMode Help 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
|
where
|
||||||
(pos,f) = case parsewithString hledgerparseerrorpositionp _essError of
|
(pos,f) = case parsewithString hledgerparseerrorpositionp _essError of
|
||||||
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 (uiReloadJournal copts d (popScreen ui)) >>= put' . uiCheckBalanceAssertions d
|
liftIO (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
|
||||||
@ -130,29 +130,27 @@ hledgerparseerrorpositionp = do
|
|||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
-- | Unconditionally reload the journal, regenerating the current screen
|
-- Defined here so it can reference the error 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
|
-- | Reload the journal from its input files, then update the ui app state accordingly.
|
||||||
-- on the error screen, update the error displayed.
|
-- This means regenerate the entire screen stack from top level down to the current screen, using the provided today-date.
|
||||||
-- Defined here so it can reference the error screen.
|
-- 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
|
-- The provided cli options can influence reloading; then if reloading succeeds they are saved in the ui state,
|
||||||
-- UIState if reloading is successful (otherwise the UIState keeps its old
|
-- otherwise the UIState keeps its old options. (XXX needed for.. ?)
|
||||||
-- CliOpts.) (XXX needed for.. ?)
|
|
||||||
--
|
--
|
||||||
-- Forecasted transactions are always generated, as at hledger-ui startup.
|
-- Like at hledger-ui startup, --forecast is always enabled.
|
||||||
-- If a forecast period is specified in the provided opts, or was specified
|
-- A forecast period specified in the provided opts, or at startup, is preserved.
|
||||||
-- at startup, it is preserved.
|
|
||||||
--
|
--
|
||||||
uiReloadJournal :: CliOpts -> Day -> UIState -> IO UIState
|
uiReload :: CliOpts -> Day -> UIState -> IO UIState
|
||||||
uiReloadJournal copts d ui = do
|
uiReload copts d ui = do
|
||||||
ej <-
|
ej <-
|
||||||
let copts' = enableForecastPreservingPeriod ui copts
|
let copts' = enableForecastPreservingPeriod ui copts
|
||||||
in runExceptT $ journalTransform copts' <$> journalReload 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
|
return $ case ej of
|
||||||
Right j ->
|
Right j ->
|
||||||
-- dbg1 "uiReloadJournal after reload" (map tdescription $ jtxns j) $
|
-- dbg1 "uiReload after reload" (map tdescription $ jtxns j) $
|
||||||
regenerateScreens j d ui
|
regenerateScreens j d ui
|
||||||
Left err ->
|
Left err ->
|
||||||
case ui of
|
case ui of
|
||||||
@ -167,11 +165,11 @@ uiReloadJournal copts d ui = do
|
|||||||
-- RegisterScreen _ _ _ _ _ _
|
-- RegisterScreen _ _ _ _ _ _
|
||||||
-- TransactionScreen _ _ _ _ _ _
|
-- 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,
|
-- have not changed since last loaded. Always regenerates the screens though,
|
||||||
-- since the provided options or today-date may have changed.
|
-- since the provided options or today-date may have changed.
|
||||||
uiReloadJournalIfChanged :: CliOpts -> Day -> Journal -> UIState -> IO UIState
|
uiReloadIfFileChanged :: CliOpts -> Day -> Journal -> UIState -> IO UIState
|
||||||
uiReloadJournalIfChanged copts d j ui = do
|
uiReloadIfFileChanged copts d j ui = do
|
||||||
let copts' = enableForecastPreservingPeriod ui copts
|
let copts' = enableForecastPreservingPeriod ui copts
|
||||||
ej <- runExceptT $ journalReloadIfChanged copts' d j
|
ej <- runExceptT $ journalReloadIfChanged copts' d j
|
||||||
return $ case ej of
|
return $ case ej of
|
||||||
|
|||||||
@ -33,7 +33,7 @@ import Hledger.UI.UITypes
|
|||||||
import Hledger.UI.UIState
|
import Hledger.UI.UIState
|
||||||
import Hledger.UI.UIUtils
|
import Hledger.UI.UIUtils
|
||||||
import Hledger.UI.UIScreens
|
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 Hledger.UI.Editor (runIadd, runEditor, endPosition)
|
||||||
import Brick.Widgets.Edit (getEditContents, handleEditorEvent)
|
import Brick.Widgets.Edit (getEditContents, handleEditorEvent)
|
||||||
import Control.Arrow ((>>>))
|
import Control.Arrow ((>>>))
|
||||||
@ -156,11 +156,11 @@ msHandle ev = do
|
|||||||
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] ->
|
||||||
liftIO (uiReloadJournal 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 >> 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)) >> uiReloadJournalIfChanged 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)) >> uiReloadJournalIfChanged 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 'B') []) -> put' $ regenerateScreens j d $ toggleConversionOp ui
|
||||||
-- VtyEvent (EvKey (KChar 'V') []) -> put' $ regenerateScreens j d $ toggleValue ui
|
-- VtyEvent (EvKey (KChar 'V') []) -> put' $ regenerateScreens j d $ toggleValue ui
|
||||||
|
|||||||
@ -43,7 +43,7 @@ import Hledger.UI.UIState
|
|||||||
import Hledger.UI.UIUtils
|
import Hledger.UI.UIUtils
|
||||||
import Hledger.UI.UIScreens
|
import Hledger.UI.UIScreens
|
||||||
import Hledger.UI.Editor
|
import Hledger.UI.Editor
|
||||||
import Hledger.UI.ErrorScreen (uiReloadJournal, uiCheckBalanceAssertions, uiReloadJournalIfChanged)
|
import Hledger.UI.ErrorScreen (uiCheckBalanceAssertions, uiReload, uiReloadIfFileChanged)
|
||||||
|
|
||||||
rsDraw :: UIState -> [Widget Name]
|
rsDraw :: UIState -> [Widget Name]
|
||||||
rsDraw UIState{aopts=_uopts@UIOpts{uoCliOpts=copts@CliOpts{reportspec_=rspec}}
|
rsDraw UIState{aopts=_uopts@UIOpts{uoCliOpts=copts@CliOpts{reportspec_=rspec}}
|
||||||
@ -246,13 +246,13 @@ rsHandle ev = do
|
|||||||
p = reportPeriod ui
|
p = reportPeriod ui
|
||||||
|
|
||||||
e | e `elem` [AppEvent FileChange, VtyEvent (EvKey (KChar 'g') [])] ->
|
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 '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 $ clearScreen >> setCursorPosition 0 0 >> add (cliOptsDropArgs copts) j >> uiReloadIfFileChanged copts d j ui
|
||||||
VtyEvent (EvKey (KChar 'A') []) -> suspendAndResume $ void (runIadd (journalFilePath j)) >> uiReloadJournalIfChanged 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 '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
|
where
|
||||||
(pos,f) = case listSelectedElement _rssList of
|
(pos,f) = case listSelectedElement _rssList of
|
||||||
Nothing -> (endPosition, journalFilePath j)
|
Nothing -> (endPosition, journalFilePath j)
|
||||||
|
|||||||
@ -29,7 +29,7 @@ import Hledger.UI.UIState
|
|||||||
import Hledger.UI.UIUtils
|
import Hledger.UI.UIUtils
|
||||||
import Hledger.UI.UIScreens
|
import Hledger.UI.UIScreens
|
||||||
import Hledger.UI.Editor
|
import Hledger.UI.Editor
|
||||||
import Hledger.UI.ErrorScreen (uiReloadJournalIfChanged, uiCheckBalanceAssertions, uiReloadJournal)
|
import Hledger.UI.ErrorScreen (uiCheckBalanceAssertions, uiReload, uiReloadIfFileChanged)
|
||||||
import Hledger.UI.RegisterScreen (rsHandle)
|
import Hledger.UI.RegisterScreen (rsHandle)
|
||||||
import System.Exit (ExitCode(..))
|
import System.Exit (ExitCode(..))
|
||||||
import Data.Function ((&))
|
import Data.Function ((&))
|
||||||
@ -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 & uiReloadJournal copts d)
|
put' =<< liftIO (popScreen ui & uiReload copts d)
|
||||||
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
|
||||||
@ -158,8 +158,8 @@ tsHandle ev = do
|
|||||||
case exitcode of
|
case exitcode of
|
||||||
ExitSuccess -> return ()
|
ExitSuccess -> return ()
|
||||||
ExitFailure c -> error' $ "running the text editor failed with exit code " ++ show c
|
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.
|
-- Update all state, similar to above.
|
||||||
put' =<< liftIO (popScreen ui & uiReloadJournalIfChanged copts d j)
|
put' =<< liftIO (popScreen ui & uiReloadIfFileChanged copts d j)
|
||||||
rsHandle (VtyEvent (EvKey KEnter []))
|
rsHandle (VtyEvent (EvKey KEnter []))
|
||||||
where (pos,f) = case tsourcepos t of (SourcePos f' l1 c1,_) -> (Just (unPos l1, Just $ unPos c1),f')
|
where (pos,f) = case tsourcepos t of (SourcePos f' l1 c1,_) -> (Just (unPos l1, Just $ unPos c1),f')
|
||||||
|
|
||||||
|
|||||||
@ -84,7 +84,7 @@ withJournalDo = withJournal
|
|||||||
-- --pivot, --anonymise error message, --obfuscate.
|
-- --pivot, --anonymise error message, --obfuscate.
|
||||||
journalTransform :: CliOpts -> Journal -> Journal
|
journalTransform :: CliOpts -> Journal -> Journal
|
||||||
journalTransform opts =
|
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.
|
-- Could it be moved down into journalFinalise ? These steps only depend on InputOpts.
|
||||||
maybePivot opts
|
maybePivot opts
|
||||||
<&> maybeWarnAboutAnon opts
|
<&> maybeWarnAboutAnon opts
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user