mirror of
https://github.com/simonmichael/hledger.git
synced 2024-11-08 07:09:28 +03:00
ui: simpler forecast toggle: just visibility, no reload (#1193)
This commit is contained in:
parent
4eba930a5c
commit
3bee9a96c9
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user