diff --git a/hledger/Hledger/Cli/Accounts.hs b/hledger/Hledger/Cli/Accounts.hs index 134ae7189..5c5a48358 100644 --- a/hledger/Hledger/Cli/Accounts.hs +++ b/hledger/Hledger/Cli/Accounts.hs @@ -56,7 +56,7 @@ accounts CliOpts{reportopts_=ropts} j = do as' | tree_ ropts = expandAccountNames as | otherwise = as render a | tree_ ropts = replicate (2 * (accountNameLevel a - 1)) ' ' ++ accountLeafName a - | otherwise = accountNameDrop (drop_ ropts) a + | otherwise = maybeAccountNameDrop ropts a mapM_ (putStrLn . render) as' tests_Hledger_Cli_Accounts = TestList [] diff --git a/hledger/Hledger/Cli/Balance.hs b/hledger/Hledger/Cli/Balance.hs index e30480e70..8e3f294ef 100644 --- a/hledger/Hledger/Cli/Balance.hs +++ b/hledger/Hledger/Cli/Balance.hs @@ -382,7 +382,7 @@ formatBalanceReportItem opts accountName depth amount (fmt:fmts) = formatField :: ReportOpts -> Maybe AccountName -> Int -> Amount -> Bool -> Maybe Int -> Maybe Int -> HledgerFormatField -> String formatField opts accountName depth total ljust min max field = case field of - AccountField -> formatValue ljust min max $ maybe "" (accountNameDrop (drop_ opts)) accountName + AccountField -> formatValue ljust min max $ maybe "" (maybeAccountNameDrop opts) accountName DepthSpacerField -> case min of Just m -> formatValue ljust Nothing max $ replicate (depth * m) ' ' Nothing -> formatValue ljust Nothing max $ replicate depth ' ' @@ -424,7 +424,7 @@ periodBalanceReportAsText opts r@(MultiBalanceReport (colspans, items, coltotals accts = map renderacct items' renderacct ((a,a',i),_) | tree_ opts = replicate ((i-1)*2) ' ' ++ a' - | otherwise = accountNameDrop (drop_ opts) a + | otherwise = maybeAccountNameDrop opts a acctswidth = maximum $ map length $ accts totalrow | no_total_ opts = row "" [] | otherwise = row "" coltotals @@ -446,7 +446,7 @@ cumulativeBalanceReportAsText opts r@(MultiBalanceReport (colspans, items, colto accts = map renderacct items renderacct ((a,a',i),_) | tree_ opts = replicate ((i-1)*2) ' ' ++ a' - | otherwise = accountNameDrop (drop_ opts) a + | otherwise = maybeAccountNameDrop opts a acctswidth = maximum $ map length $ accts addtotalrow | no_total_ opts = id | otherwise = (+----+ row "" coltotals) @@ -468,7 +468,7 @@ historicalBalanceReportAsText opts r@(MultiBalanceReport (colspans, items, colto accts = map renderacct items renderacct ((a,a',i),_) | tree_ opts = replicate ((i-1)*2) ' ' ++ a' - | otherwise = accountNameDrop (drop_ opts) a + | otherwise = maybeAccountNameDrop opts a acctswidth = maximum $ map length $ accts addtotalrow | no_total_ opts = id | otherwise = (+----+ row "" coltotals) diff --git a/hledger/Hledger/Cli/Options.hs b/hledger/Hledger/Cli/Options.hs index 50a7bd67a..ad15697c9 100644 --- a/hledger/Hledger/Cli/Options.hs +++ b/hledger/Hledger/Cli/Options.hs @@ -49,6 +49,7 @@ module Hledger.Cli.Options ( defaultWidth, defaultWidthWithFlag, widthFromOpts, + maybeAccountNameDrop, -- | For balance: lineFormatFromOpts, @@ -465,6 +466,11 @@ widthp :: Stream [Char] m t => ParsecT [Char] st m Width widthp = (string "auto" >> return Auto) <|> (Width . read) `fmap` many1 digit +-- | Drop leading components of accounts names as specified by --drop, but only in --flat mode. +maybeAccountNameDrop :: ReportOpts -> AccountName -> AccountName +maybeAccountNameDrop opts a | tree_ opts = a + | otherwise = accountNameDrop (drop_ opts) a + -- Other utils -- | Get the sorted unique precise names and display names of hledger