From 6ce5e85e99f301fbc4f3bedd992663a0856c9b19 Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Tue, 8 Oct 2024 22:22:57 -1000 Subject: [PATCH] dev: clarify: rename displayDepth/prrDepth to displayIndent/prrIndent These are about indentation for rendering, not account depth; these are not always directly related, eg when boring parents are elided. --- hledger-lib/Hledger/Reports/BalanceReport.hs | 2 +- .../Hledger/Reports/MultiBalanceReport.hs | 2 +- hledger-lib/Hledger/Reports/ReportTypes.hs | 26 +++++++++++-------- hledger/Hledger/Cli/Commands/Balance.hs | 4 +-- 4 files changed, 19 insertions(+), 15 deletions(-) diff --git a/hledger-lib/Hledger/Reports/BalanceReport.hs b/hledger-lib/Hledger/Reports/BalanceReport.hs index 4cef9ab08..0512e35c5 100644 --- a/hledger-lib/Hledger/Reports/BalanceReport.hs +++ b/hledger-lib/Hledger/Reports/BalanceReport.hs @@ -71,7 +71,7 @@ balanceReport rspec j = (rows, total) report = multiBalanceReport rspec j rows = [( prrFullName row , prrDisplayName row - , prrDepth row - 1 -- BalanceReport uses 0-based account depths + , prrIndent row - 1 -- BalanceReport uses 0-based account depths , prrTotal row ) | row <- prRows report] total = prrTotal $ prTotals report diff --git a/hledger-lib/Hledger/Reports/MultiBalanceReport.hs b/hledger-lib/Hledger/Reports/MultiBalanceReport.hs index d6a028224..3468ada44 100644 --- a/hledger-lib/Hledger/Reports/MultiBalanceReport.hs +++ b/hledger-lib/Hledger/Reports/MultiBalanceReport.hs @@ -601,7 +601,7 @@ tests_MultiBalanceReport = testGroup "MultiBalanceReport" [ (eitems, etotal) = r (PeriodicReport _ aitems atotal) = multiBalanceReport rspec' journal showw (PeriodicReportRow a lAmt amt amt') - = (displayFull a, displayName a, displayDepth a, map showMixedAmountDebug lAmt, showMixedAmountDebug amt, showMixedAmountDebug amt') + = (displayFull a, displayName a, displayIndent a, map showMixedAmountDebug lAmt, showMixedAmountDebug amt, showMixedAmountDebug amt') (map showw aitems) @?= (map showw eitems) showMixedAmountDebug (prrTotal atotal) @?= showMixedAmountDebug etotal -- we only check the sum of the totals in diff --git a/hledger-lib/Hledger/Reports/ReportTypes.hs b/hledger-lib/Hledger/Reports/ReportTypes.hs index e3007dd8f..8868257b9 100644 --- a/hledger-lib/Hledger/Reports/ReportTypes.hs +++ b/hledger-lib/Hledger/Reports/ReportTypes.hs @@ -31,7 +31,7 @@ module Hledger.Reports.ReportTypes , prrShowDebug , prrFullName , prrDisplayName -, prrDepth +, prrIndent , prrAdd ) where @@ -211,11 +211,16 @@ data CBCSubreportSpec a = CBCSubreportSpec } --- | A full name, display name, and depth for an account. +-- | The number of indentation steps with which to display a report item. +-- 0 means no indentation. 1 means one indent step, which is normally rendered +-- as two spaces in text output, or two no-break spaces in csv/html output. +type NumberOfIndents = Int + +-- | A full name, display name, and indent level for an account. data DisplayName = DisplayName - { displayFull :: AccountName - , displayName :: AccountName - , displayDepth :: Int + { displayFull :: AccountName + , displayName :: AccountName + , displayIndent :: NumberOfIndents } deriving (Show, Eq, Ord) instance ToJSON DisplayName where @@ -232,15 +237,14 @@ flatDisplayName a = DisplayName a a 1 treeDisplayName :: AccountName -> DisplayName treeDisplayName a = DisplayName a (accountLeafName a) (accountNameLevel a) --- | Get the full, canonical, name of a PeriodicReportRow tagged by a --- DisplayName. +-- | Get the full canonical account name from a PeriodicReportRow containing a DisplayName. prrFullName :: PeriodicReportRow DisplayName a -> AccountName prrFullName = displayFull . prrName --- | Get the display name of a PeriodicReportRow tagged by a DisplayName. +-- | Get the account display name from a PeriodicReportRow containing a DisplayName. prrDisplayName :: PeriodicReportRow DisplayName a -> AccountName prrDisplayName = displayName . prrName --- | Get the display depth of a PeriodicReportRow tagged by a DisplayName. -prrDepth :: PeriodicReportRow DisplayName a -> Int -prrDepth = displayDepth . prrName +-- | Get the indent level from a PeriodicReportRow containing a DisplayName. +prrIndent :: PeriodicReportRow DisplayName a -> Int +prrIndent = displayIndent . prrName diff --git a/hledger/Hledger/Cli/Commands/Balance.hs b/hledger/Hledger/Cli/Commands/Balance.hs index fe5c1040a..6fa3c9b32 100644 --- a/hledger/Hledger/Cli/Commands/Balance.hs +++ b/hledger/Hledger/Cli/Commands/Balance.hs @@ -932,7 +932,7 @@ multiBalanceReportAsTable opts@ReportOpts{summary_only_, average_, row_total_, b in (replicate (length rs) (renderacct row), rs) (accts, rows) = unzip $ fmap fullRowAsTexts items renderacct row = - T.replicate ((prrDepth row - 1) * 2) " " <> prrDisplayName row + T.replicate ((prrIndent row - 1) * 2) " " <> prrDisplayName row addtotalrow | no_total_ opts = id | otherwise = @@ -1343,7 +1343,7 @@ renderPeriodicAcct :: ReportOpts -> Text -> PeriodicReportRow DisplayName a -> Text renderPeriodicAcct opts space row = renderBalanceAcct opts space - (prrFullName row, prrDisplayName row, prrDepth row - 1) + (prrFullName row, prrDisplayName row, prrIndent row - 1) -- tests