dev:ui:refactor, rename enableForecast

This commit is contained in:
Simon Michael 2025-09-11 23:44:34 +01:00
parent 53bd228973
commit 51842034dd
2 changed files with 13 additions and 14 deletions

View File

@ -145,7 +145,7 @@ hledgerparseerrorpositionp = do
uiReload :: CliOpts -> Day -> UIState -> IO UIState uiReload :: CliOpts -> Day -> UIState -> IO UIState
uiReload copts d ui = do uiReload copts d ui = do
ej <- ej <-
let copts' = enableForecastPreservingPeriod ui copts let copts' = enableForecast (astartupopts ui) copts
in runExceptT $ journalTransform copts' <$> journalReload copts' in runExceptT $ journalTransform copts' <$> journalReload copts'
-- dbg1IO "uiReload before reload" (map tdescription $ jtxns $ ajournal ui) -- dbg1IO "uiReload before reload" (map tdescription $ jtxns $ ajournal ui)
return $ case ej of return $ case ej of
@ -170,7 +170,7 @@ uiReload copts d ui = do
-- since the provided options or today-date may have changed. -- since the provided options or today-date may have changed.
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' = enableForecastPreservingPeriod ui copts let copts' = enableForecast (astartupopts ui) copts
ej <- runExceptT $ journalReloadIfChanged copts' d j ej <- runExceptT $ journalReloadIfChanged copts' d j
return $ case ej of return $ case ej of
Right (j', _) -> regenerateScreens j' d ui Right (j', _) -> regenerateScreens j' d ui

View File

@ -35,7 +35,7 @@ module Hledger.UI.UIState
,resetDepth ,resetDepth
,popScreen ,popScreen
,pushScreen ,pushScreen
,enableForecastPreservingPeriod ,enableForecast
,resetFilter ,resetFilter
,resetScreens ,resetScreens
,regenerateScreens ,regenerateScreens
@ -202,19 +202,18 @@ toggleForecast _d ui = set forecast newForecast ui
where where
newForecast = case ui^.forecast of newForecast = case ui^.forecast of
Just _ -> Nothing Just _ -> Nothing
Nothing -> enableForecastPreservingPeriod ui (ui^.cliOpts) ^. forecast Nothing -> enableForecast (astartupopts ui) (ui^.cliOpts) ^. forecast
-- | Ensure this CliOpts enables forecasted transactions. -- | Enable forecasting in this CliOpts.
-- If a forecast period was specified in the old CliOpts, -- If it previously specified a forecast period, or else if the given ui startup options did,
-- or in the provided UIState's startup options, -- preserve that as the forecast period.
-- it is preserved. enableForecast :: UIOpts -> CliOpts -> CliOpts
enableForecastPreservingPeriod :: UIState -> CliOpts -> CliOpts enableForecast startopts currentopts = set forecast mforecast currentopts
enableForecastPreservingPeriod ui copts = set forecast mforecast copts
where where
mforecast = asum [mprovidedforecastperiod, mstartupforecastperiod, mdefaultforecastperiod] mforecast = asum [mcurrentforecastperiod, mstartupforecastperiod, mdefaultforecastperiod]
where where
mprovidedforecastperiod = copts ^. forecast mcurrentforecastperiod = currentopts ^. forecast
mstartupforecastperiod = astartupopts ui ^. forecast mstartupforecastperiod = startopts ^. forecast
mdefaultforecastperiod = Just nulldatespan mdefaultforecastperiod = Just nulldatespan
-- | Toggle between showing all and showing only real (non-virtual) items. -- | Toggle between showing all and showing only real (non-virtual) items.