From 3bee9a96c93701cbd607c44dab66a11455ed285a Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Sat, 22 Feb 2020 11:02:30 -0800 Subject: [PATCH] ui: simpler forecast toggle: just visibility, no reload (#1193) --- hledger-ui/Hledger/UI/AccountsScreen.hs | 20 ++++++++++---------- hledger-ui/Hledger/UI/Main.hs | 19 +++++++++++-------- hledger-ui/Hledger/UI/RegisterScreen.hs | 21 ++++++++++----------- 3 files changed, 31 insertions(+), 29 deletions(-) diff --git a/hledger-ui/Hledger/UI/AccountsScreen.hs b/hledger-ui/Hledger/UI/AccountsScreen.hs index 4a26f385d..093c02e04 100644 --- a/hledger-ui/Hledger/UI/AccountsScreen.hs +++ b/hledger-ui/Hledger/UI/AccountsScreen.hs @@ -83,13 +83,15 @@ asInit d reset ui@UIState{ uopts' = uopts{cliopts_=copts{reportopts_=ropts'}} ropts' = ropts{accountlistmode_=if tree_ ropts then ALTree else ALFlat} - q = And [queryFromOpts d ropts - -- Exclude future transactions except in forecast mode - -- XXX this necessitates special handling in multiBalanceReport, at least - ,if forecast_ ropts - then Any - else Date $ DateSpan Nothing (Just $ addDays 1 d) - ] + q = And [queryFromOpts d ropts, excludeforecastq (forecast_ ropts)] + where + -- Except in forecast mode, exclude future/forecast transactions. + excludeforecastq True = Any + excludeforecastq False = -- not:date:tomorrow- not:tag:generated-transaction + And [ + Not (Date $ DateSpan (Just $ addDays 1 d) Nothing) + ,Not (Tag "generated-transaction" Nothing) + ] -- run the report (items,_total) = report ropts' q j @@ -337,9 +339,7 @@ asHandle ui0@UIState{ VtyEvent (EvKey (KChar 'U') []) -> asCenterAndContinue $ regenerateScreens j d $ toggleUnmarked ui VtyEvent (EvKey (KChar 'P') []) -> asCenterAndContinue $ regenerateScreens j d $ togglePending ui VtyEvent (EvKey (KChar 'C') []) -> asCenterAndContinue $ regenerateScreens j d $ toggleCleared ui - VtyEvent (EvKey (KChar 'F') []) -> - let ui'@UIState{aopts=UIOpts{cliopts_=copts'}} = toggleForecast ui - in liftIO (uiReloadJournal copts' d ui') >>= continue + VtyEvent (EvKey (KChar 'F') []) -> continue $ regenerateScreens j d $ toggleForecast ui VtyEvent (EvKey (KDown) [MShift]) -> continue $ regenerateScreens j d $ shrinkReportPeriod d ui VtyEvent (EvKey (KUp) [MShift]) -> continue $ regenerateScreens j d $ growReportPeriod d ui diff --git a/hledger-ui/Hledger/UI/Main.hs b/hledger-ui/Hledger/UI/Main.hs index 102d0b3f5..5580e2c81 100644 --- a/hledger-ui/Hledger/UI/Main.hs +++ b/hledger-ui/Hledger/UI/Main.hs @@ -62,15 +62,18 @@ writeChan = BC.writeBChan main :: IO () main = do - opts <- getHledgerUIOpts + opts@UIOpts{cliopts_=copts@CliOpts{inputopts_=_iopts,reportopts_=ropts,rawopts_=rawopts}} <- getHledgerUIOpts -- when (debug_ $ cliopts_ opts) $ printf "%s\n" prognameandversion >> printf "opts: %s\n" (show opts) - run opts - where - run opts - | "help" `inRawOpts` (rawopts_ $ cliopts_ opts) = putStr (showModeUsage uimode) >> exitSuccess - | "version" `inRawOpts` (rawopts_ $ cliopts_ opts) = putStrLn prognameandversion >> exitSuccess - | "binary-filename" `inRawOpts` (rawopts_ $ cliopts_ opts) = putStrLn (binaryfilename progname) - | otherwise = withJournalDo (cliopts_ opts) (runBrickUi opts) + + -- always include forecasted periodic transactions when loading data; + -- they will be toggled on and off in the UI. + let copts' = copts{reportopts_=ropts{forecast_=True}} + + case True of + _ | "help" `inRawOpts` rawopts -> putStr (showModeUsage uimode) >> exitSuccess + _ | "version" `inRawOpts` rawopts -> putStrLn prognameandversion >> exitSuccess + _ | "binary-filename" `inRawOpts` rawopts -> putStrLn (binaryfilename progname) + _ -> withJournalDo copts' (runBrickUi opts) runBrickUi :: UIOpts -> Journal -> IO () runBrickUi uopts@UIOpts{cliopts_=copts@CliOpts{inputopts_=_iopts,reportopts_=ropts}} j = do diff --git a/hledger-ui/Hledger/UI/RegisterScreen.hs b/hledger-ui/Hledger/UI/RegisterScreen.hs index cee71152b..25fd92d1b 100644 --- a/hledger-ui/Hledger/UI/RegisterScreen.hs +++ b/hledger-ui/Hledger/UI/RegisterScreen.hs @@ -69,14 +69,15 @@ rsInit d reset ui@UIState{aopts=_uopts@UIOpts{cliopts_=CliOpts{reportopts_=ropts ropts' = ropts{ depth_=Nothing } - q = And [queryFromOpts d ropts' - -- Exclude future transactions except in forecast mode - -- XXX this necessitates special handling in multiBalanceReport, at least - ,if forecast_ ropts - then Any - else Date $ DateSpan Nothing (Just $ addDays 1 d) - ] --- reportq = filterQuery (not . queryIsDepth) q + q = And [queryFromOpts d ropts, excludeforecastq (forecast_ ropts)] + where + -- Except in forecast mode, exclude future/forecast transactions. + excludeforecastq True = Any + excludeforecastq False = -- not:date:tomorrow- not:tag:generated-transaction + And [ + Not (Date $ DateSpan (Just $ addDays 1 d) Nothing) + ,Not (Tag "generated-transaction" Nothing) + ] (_label,items) = accountTransactionsReport ropts' j q thisacctq items' = (if empty_ ropts' then id else filter (not . isZeroMixedAmount . fifth6)) $ -- without --empty, exclude no-change txns @@ -335,9 +336,7 @@ rsHandle ui@UIState{ VtyEvent (EvKey (KChar 'U') []) -> rsCenterAndContinue $ regenerateScreens j d $ toggleUnmarked ui VtyEvent (EvKey (KChar 'P') []) -> rsCenterAndContinue $ regenerateScreens j d $ togglePending ui VtyEvent (EvKey (KChar 'C') []) -> rsCenterAndContinue $ regenerateScreens j d $ toggleCleared ui - VtyEvent (EvKey (KChar 'F') []) -> - let ui'@UIState{aopts=UIOpts{cliopts_=copts'}} = toggleForecast ui - in liftIO (uiReloadJournal copts' d ui') >>= rsCenterAndContinue + VtyEvent (EvKey (KChar 'F') []) -> rsCenterAndContinue $ regenerateScreens j d $ toggleForecast ui VtyEvent (EvKey (KChar '/') []) -> continue $ regenerateScreens j d $ showMinibuffer ui VtyEvent (EvKey (KDown) [MShift]) -> continue $ regenerateScreens j d $ shrinkReportPeriod d ui