From ffb40870ce246b06bb6e0c3e3d92cda20d901ce5 Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Tue, 26 Jul 2016 17:28:29 -0700 Subject: [PATCH] ui: register: be inclusive for a depth-clipped account, matching displayed balance And drop F key from register screen again. --- hledger-ui/Hledger/UI/AccountsScreen.hs | 5 ++++- hledger-ui/Hledger/UI/Main.hs | 2 +- hledger-ui/Hledger/UI/RegisterScreen.hs | 18 ++++++++++++------ hledger-ui/Hledger/UI/UIState.hs | 3 +++ hledger-ui/Hledger/UI/UITypes.hs | 5 ++++- hledger-ui/doc/hledger-ui.1.m4.md | 20 ++++++++++++-------- 6 files changed, 36 insertions(+), 17 deletions(-) diff --git a/hledger-ui/Hledger/UI/AccountsScreen.hs b/hledger-ui/Hledger/UI/AccountsScreen.hs index 5ec3ec0a6..4c8d0d1f2 100644 --- a/hledger-ui/Hledger/UI/AccountsScreen.hs +++ b/hledger-ui/Hledger/UI/AccountsScreen.hs @@ -297,7 +297,10 @@ asHandle ui0@UIState{ EvKey k [] | k `elem` [KLeft, KChar 'h'] -> continue $ popScreen ui EvKey k [] | k `elem` [KRight, KChar 'l', KEnter] -> scrollTopRegister >> continue (screenEnter d scr ui) where - scr = rsSetAccount selacct registerScreen + scr = rsSetAccount selacct isdepthclipped registerScreen + isdepthclipped = case getDepth ui of + Just d -> accountNameLevel selacct >= d + Nothing -> False -- fall through to the list's event handler (handles up/down) ev -> do diff --git a/hledger-ui/Hledger/UI/Main.hs b/hledger-ui/Hledger/UI/Main.hs index d92b511a4..92b750dec 100644 --- a/hledger-ui/Hledger/UI/Main.hs +++ b/hledger-ui/Hledger/UI/Main.hs @@ -101,7 +101,7 @@ runBrickUi uopts@UIOpts{cliopts_=copts@CliOpts{reportopts_=ropts}} j = do -- with --register, start on the register screen, and also put -- the accounts screen on the prev screens stack so you can exit -- to that as usual. - Just apat -> (rsSetAccount acct registerScreen, [ascr']) + Just apat -> (rsSetAccount acct False registerScreen, [ascr']) where acct = headDef (error' $ "--register "++apat++" did not match any account") diff --git a/hledger-ui/Hledger/UI/RegisterScreen.hs b/hledger-ui/Hledger/UI/RegisterScreen.hs index 530cde704..3001c5ce7 100644 --- a/hledger-ui/Hledger/UI/RegisterScreen.hs +++ b/hledger-ui/Hledger/UI/RegisterScreen.hs @@ -44,23 +44,28 @@ registerScreen = RegisterScreen{ ,sHandle = rsHandle ,rsList = list RegisterList V.empty 1 ,rsAccount = "" + ,rsForceInclusive = False } -rsSetAccount a scr@RegisterScreen{} = scr{rsAccount=replaceHiddenAccountsNameWith "*" a} -rsSetAccount _ scr = scr +rsSetAccount :: AccountName -> Bool -> Screen -> Screen +rsSetAccount a forceinclusive scr@RegisterScreen{} = + scr{rsAccount=replaceHiddenAccountsNameWith "*" a, rsForceInclusive=forceinclusive} +rsSetAccount _ _ scr = scr rsInit :: Day -> Bool -> UIState -> UIState rsInit d reset ui@UIState{aopts=UIOpts{cliopts_=CliOpts{reportopts_=ropts}}, ajournal=j, aScreen=s@RegisterScreen{..}} = ui{aScreen=s{rsList=newitems'}} where -- gather arguments and queries + -- XXX temp + inclusive = not (flat_ ropts) || rsForceInclusive + thisacctq = Acct $ (if inclusive then accountNameToAccountRegex else accountNameToAccountOnlyRegex) rsAccount ropts' = ropts{ depth_=Nothing ,balancetype_=HistoricalBalance } - -- XXX temp - thisacctq = Acct $ (if flat_ ropts then accountNameToAccountOnlyRegex else accountNameToAccountRegex) rsAccount - q = filterQuery (not . queryIsDepth) $ queryFromOpts d ropts' + q = queryFromOpts d ropts' +-- reportq = filterQuery (not . queryIsDepth) q (_label,items) = accountTransactionsReport ropts' j q thisacctq items' = (if empty_ ropts' then id else filter (not . isZeroMixedAmount . fifth6)) $ -- without --empty, exclude no-change txns @@ -108,9 +113,10 @@ rsDraw UIState{aopts=UIOpts{cliopts_=copts@CliOpts{reportopts_=ropts}} -- Minibuffer e -> [minibuffer e, maincontent] _ -> [maincontent] where + inclusive = not (flat_ ropts) || rsForceInclusive toplabel = withAttr ("border" <> "bold") (str $ T.unpack $ replaceHiddenAccountsNameWith "All" rsAccount) - <+> withAttr (borderAttr <> "query") (str $ if flat_ ropts then " (exclusive)" else "") + <+> withAttr (borderAttr <> "query") (str $ if inclusive then "" else " (exclusive)") <+> togglefilters <+> str " transactions" <+> borderQueryStr (query_ ropts) diff --git a/hledger-ui/Hledger/UI/UIState.hs b/hledger-ui/Hledger/UI/UIState.hs index 7e537cf77..4c6f7b232 100644 --- a/hledger-ui/Hledger/UI/UIState.hs +++ b/hledger-ui/Hledger/UI/UIState.hs @@ -123,6 +123,9 @@ setDepth mdepth ui@UIState{aopts=uopts@UIOpts{cliopts_=copts@CliOpts{reportopts_ | d >= maxDepth ui -> Nothing | otherwise -> mdepth +getDepth :: UIState -> Maybe Int +getDepth UIState{aopts=UIOpts{cliopts_=CliOpts{reportopts_=ropts}}} = depth_ ropts + -- | Open the minibuffer, setting its content to the current query with the cursor at the end. showMinibuffer :: UIState -> UIState showMinibuffer ui = setMode (Minibuffer e) ui diff --git a/hledger-ui/Hledger/UI/UITypes.hs b/hledger-ui/Hledger/UI/UITypes.hs index 76e222382..804b21dd4 100644 --- a/hledger-ui/Hledger/UI/UITypes.hs +++ b/hledger-ui/Hledger/UI/UITypes.hs @@ -105,8 +105,11 @@ data Screen = ,sDraw :: UIState -> [Widget Name] ,sHandle :: UIState -> Event -> EventM Name (Next UIState) -- - ,rsList :: List Name RegisterScreenItem -- ^ list widget showing transactions affecting this account + ,rsList :: List Name RegisterScreenItem -- ^ list widget showing transactions affecting this account ,rsAccount :: AccountName -- ^ the account this register is for + ,rsForceInclusive :: Bool -- ^ should this register always include subaccount transactions, + -- even when in flat mode ? (ie because entered from a + -- depth-clipped accounts screen item) } | TransactionScreen { sInit :: Day -> Bool -> UIState -> UIState diff --git a/hledger-ui/doc/hledger-ui.1.m4.md b/hledger-ui/doc/hledger-ui.1.m4.md index c6a9b074d..dfbb713fc 100644 --- a/hledger-ui/doc/hledger-ui.1.m4.md +++ b/hledger-ui/doc/hledger-ui.1.m4.md @@ -124,7 +124,7 @@ Additional screen-specific keys are described below. This is normally the first screen displayed. It lists accounts and their balances, like hledger's balance command. -By default, it shows all accounts and their latest ending balances. +By default, it shows all accounts and their latest ending balances (including the balances of subaccounts). if you specify a query on the command line, it shows just the matched accounts and the balances from matched transactions. Account names are normally indented to show the hierarchy (tree mode). @@ -133,8 +133,9 @@ To see less detail, set a depth limit by pressing a number key, `1` to `9`. `-` and `+` (or `=`) decrease and increase the depth limit. To remove the depth limit, set it higher than the maximum account depth, or press `ESCAPE`. -`F` toggles flat mode on and off. In flat mode, accounts are listed without indentation -(and account registers will exclude subaccounts, see below). +`F` toggles flat mode on and off. In flat mode, accounts are listed without indentation, +and show their subaccount-excluding balances, except for accounts which have been clipped +by a depth limit, which show their inclusive balances (as with hledger's balance command). `C` toggles cleared mode, in which [uncleared transactions and postings](/journal.html#transactions) are @@ -179,11 +180,14 @@ Each line represents one transaction and shows: $ hledger-ui --register checking --cleared ``` -Normally the register screen shows transactions in the current account and any of its subaccounts -(inclusive mode). If it was entered from accounts screen in flat mode, -it shows transactions affecting this account specifically, without -considering subaccounts (exclusive mode). -As on the accounts screen you can toggle this with the `F` key. +The register screen normally shows transactions in the current account +and any of its subaccounts (inclusive mode). +If it was entered from the accounts screen in flat mode, where the +selected account was not depth-clipped and therefore was showing its +subaccount-excluding balance, the register too will omit the transactions +of subaccounts (exclusive mode). This means the register always shows +the transactions responsible for the balance being displayed on the +accounts screen. `C` toggles cleared mode, in which [uncleared transactions and postings](/journal.html#transactions) are