Skip to content

Commit ebe770d

Browse files
committed
imp:cli:aregister: --title now sets the report heading
aregister's "Transactions in ACCT and subaccounts:" heading was hardcoded; it is now the default for --title, so it can be replaced with --title=TEXT or suppressed with --title=. --heading=no still suppresses it as before. AI usage: Claude Opus 5, ~15k output tokens
1 parent d302fc1 commit ebe770d

3 files changed

Lines changed: 25 additions & 4 deletions

File tree

hledger/Hledger/Cli/Commands/Aregister.hs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ aregister opts@CliOpts{rawopts_=rawopts,reportspec_=rspec} j = do
121121
(if empty_ ropts' then id else filter (not . mixedAmountLooksZero . fifth6)) $
122122
reverse items
123123
-- select renderer
124-
render | fmt=="txt" = withTitle ropts' . accountTransactionsReportAsText opts (_rsQuery rspec') thisacctq
124+
render | fmt=="txt" = accountTransactionsReportAsText opts (_rsQuery rspec') thisacctq
125125
| fmt=="html" = accountTransactionsReportAsHTML opts (_rsQuery rspec') thisacctq
126126
| fmt=="csv" = printCSV . accountTransactionsReportAsCsv opts hd wd (_rsQuery rspec') thisacctq
127127
| fmt=="tsv" = printTSV . accountTransactionsReportAsCsv opts hd wd (_rsQuery rspec') thisacctq
@@ -208,7 +208,7 @@ accountTransactionsReportAsHTML copts reportq thisacctq items =
208208
-- | Render a register report as plain text suitable for console output.
209209
accountTransactionsReportAsText :: CliOpts -> Query -> Query -> AccountTransactionsReport -> TL.Text
210210
accountTransactionsReportAsText copts reportq thisacctq items = TB.toLazyText $
211-
(optional (headingopt copts) $ acctHeading <> TB.singleton '\n')
211+
titleBuilder
212212
<>
213213
postingsOrTransactionsReportAsText alignAll copts itemAsText itemamt itembal items
214214
where
@@ -217,8 +217,12 @@ accountTransactionsReportAsText copts reportq thisacctq items = TB.toLazyText $
217217
itemamt (_,_,_,_,a,_) = a
218218
itembal (_,_,_,_,_,a) = a
219219

220+
title = effectiveTitle (_rsReportOpts $ reportspec_ copts) defaultTitle
221+
titleBuilder | not (headingopt copts) || T.null title = mempty
222+
| otherwise = TB.fromText title <> TB.singleton '\n'
223+
220224
-- show a heading indicating which account was picked, which can be confusing otherwise
221-
acctHeading = maybe mempty (\s -> foldMap TB.fromText ["Transactions in ", s, " and subaccounts", qmsg, ":"]) macct
225+
defaultTitle = maybe "" (\s -> T.concat ["Transactions in ", s, " and subaccounts", qmsg, ":"]) macct
222226
where
223227
-- XXX temporary hack ? recover the account name from the query
224228
macct = case filterQuery queryIsAcct thisacctq of

hledger/hledger.m4.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5678,7 +5678,7 @@ Examples:
56785678

56795679
# Report titles
56805680

5681-
Some reports (`balancesheet`, `balancesheetequity`, `cashflow`, `incomestatement`) are displayed with
5681+
Some reports (`aregister`, `balance` (multi-period), `balancesheet`, `balancesheetequity`, `cashflow`, `holdings`, `incomestatement`) are displayed with
56825682
a title by default, and others are not. For most reports you can set a title with `--title='Some Text'`,
56835683
or suppress the title with `--title=`.
56845684

hledger/test/aregister.test

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,3 +142,20 @@ Transactions in a and subaccounts:
142142
$ hledger -f - areg d --drop 1
143143
Transactions in d and subaccounts:
144144
2025-06-12 b, c $-2 $-2
145+
146+
# ** 10. --title replaces the default heading.
147+
<
148+
2025-06-12
149+
(a) $1
150+
151+
$ hledger -f - areg a --title 'My Title'
152+
My Title
153+
2025-06-12 a $1 $1
154+
155+
# ** 11. An empty --title suppresses the heading.
156+
<
157+
2025-06-12
158+
(a) $1
159+
160+
$ hledger -f - areg a --title=
161+
2025-06-12 a $1 $1

0 commit comments

Comments
 (0)