mirror of
https://github.com/simonmichael/hledger.git
synced 2024-11-08 07:09:28 +03:00
fix, show only top level by default
This commit is contained in:
parent
a881f713c1
commit
7d2a868640
16
Account.hs
16
Account.hs
@ -106,16 +106,16 @@ isBoringAccount2 l a
|
||||
txns = transactionsInAccountNamed l a
|
||||
subs = subAccountNamesFrom (ledgerAccountNames l) a
|
||||
|
||||
ledgerAccountTreeMatching :: Ledger -> Bool -> [String] -> Tree Account
|
||||
ledgerAccountTreeMatching l showsubs [] =
|
||||
ledgerAccountTreeMatching l showsubs [".*"]
|
||||
ledgerAccountTreeMatching l showsubs acctpats =
|
||||
ledgerAccountTreeMatching :: Ledger -> [String] -> Bool -> Int -> Tree Account
|
||||
ledgerAccountTreeMatching l [] showsubs maxdepth =
|
||||
ledgerAccountTreeMatching l [".*"] showsubs maxdepth
|
||||
ledgerAccountTreeMatching l acctpats showsubs maxdepth =
|
||||
addDataToAccountNameTree l $
|
||||
filterAccountNameTree acctpats showsubs $
|
||||
filterAccountNameTree acctpats showsubs maxdepth $
|
||||
ledgerAccountNameTree l
|
||||
|
||||
showLedgerAccounts :: Ledger -> Bool -> [String] -> String
|
||||
showLedgerAccounts l showsubs acctpats =
|
||||
showLedgerAccounts :: Ledger -> [String] -> Bool -> Int -> String
|
||||
showLedgerAccounts l acctpats showsubs maxdepth =
|
||||
concatMap
|
||||
(showAccountTree l 999 0)
|
||||
(branches (ledgerAccountTreeMatching l showsubs acctpats))
|
||||
(branches (ledgerAccountTreeMatching l acctpats showsubs maxdepth))
|
||||
|
@ -82,9 +82,10 @@ showAccountNameTree t =
|
||||
where
|
||||
topacct = indentAccountName 0 $ root t
|
||||
|
||||
filterAccountNameTree :: [String] -> Bool -> Tree AccountName -> Tree AccountName
|
||||
filterAccountNameTree pats keepsubs =
|
||||
treefilter $ \a -> matchpats a || (keepsubs && issubofmatch a)
|
||||
filterAccountNameTree :: [String] -> Bool -> Int -> Tree AccountName -> Tree AccountName
|
||||
filterAccountNameTree pats keepsubs maxdepth =
|
||||
treefilter (\a -> matchpats a || (keepsubs && issubofmatch a)) .
|
||||
treeprune maxdepth
|
||||
where
|
||||
matchpats a = any (match a) pats
|
||||
match a pat = matchAccountName pat $ accountLeafName a
|
||||
|
6
Utils.hs
6
Utils.hs
@ -42,6 +42,12 @@ tildeExpand xs = return xs
|
||||
root = rootLabel
|
||||
branches = subForest
|
||||
|
||||
-- remove all nodes past a certain depth
|
||||
treeprune :: Int -> Tree a -> Tree a
|
||||
treeprune 0 t = Node (root t) []
|
||||
treeprune d t =
|
||||
Node (root t) (map (treeprune $ d-1) $ branches t)
|
||||
|
||||
-- apply f to all tree nodes
|
||||
treemap :: (a -> b) -> Tree a -> Tree b
|
||||
treemap f t = Node (f $ root t) (map (treemap f) $ branches t)
|
||||
|
@ -87,9 +87,12 @@ printRegister opts args ledger = do
|
||||
|
||||
printBalance :: [Flag] -> [String] -> Ledger -> IO ()
|
||||
printBalance opts args ledger = do
|
||||
putStr $ showLedgerAccounts ledger showsubs acctpats
|
||||
putStr $ showLedgerAccounts ledger acctpats showsubs maxdepth
|
||||
where
|
||||
showsubs = (ShowSubs `elem` opts)
|
||||
(acctpats,_) = ledgerPatternArgs args
|
||||
showsubs = (ShowSubs `elem` opts)
|
||||
maxdepth = case (acctpats, showsubs) of
|
||||
([],False) -> 1
|
||||
otherwise -> 9999
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user