Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

print fixes, new amount styling api #2080

Merged
merged 14 commits into from
Sep 2, 2023
Merged

Conversation

simonmichael
Copy link
Owner

@simonmichael simonmichael commented Aug 31, 2023

This is a rather extensive set of changes to fix a few issues with print.

Internal changes:

There's a new, consolidated amount styling api, with a new HasAmounts
typeclass. More cleanup is possible.

AmountStyle now makes setting the precision optional.
This simplifies the code for styling amounts, but it complicates
the semantics (Nothing is useful only when setting style).
Not sure if it's the best way.
Also some other fields have been renamed/reordered more mnemonically.

Reports now typically do a final amount styling pass, where they can
tweak amount rendering if needed (and can style only the amounts they
are rendering).

An internal styling pass when converting to cost is no longer needed
and has been dropped. (The initial styling pass in journalFinalise
could perhaps be dropped some day, but for now it is still needed.)

User-visible changes:

print now styles costs in balance assertions consistently.

print no longer does inappropriate rounding in implicit conversions (#2079).

print now shows a disambiguating decimal mark when needed,
for clarity and reparseability.
Eg "1,000" (with , as a thousands separator and no decimal digits) is
now displayed with a decimal mark: "1,000.".
"1 000" (where space is a thousands separator) is less ambiguous,
but we do the same thing (eg "1 000.") for consistency, and also to
help disambiguate when forgetting to quote a numeric commodity symbol
(eg "1234 0" where 1234 is a symbol that should have been in double quotes).

Since this type is about to change anyway.
This simplifies the code for styling amounts with or without precision.
But it complicates the semantics (Nothing is useful only when setting style).
Not sure if it's the best way.
Eg "1,000" (with , as a thousands separator and no decimal digits) is
now displayed with a decimal mark: "1,000.".

"1 000" (where space is a thousands separator) is less ambiguous,
but we do the same thing (eg "1 000.") for consistency, and also to
help disambiguate when forgetting to quote a numeric commodity symbol
(eg "1234 0" where 1234 is a symbol that should have been in double quotes).
@simonmichael simonmichael added A-WISH Some kind of improvement request, hare-brained proposal, or plea. print labels Aug 31, 2023
@simonmichael simonmichael changed the title 2023 08 print style print fixes, new amount styling api Aug 31, 2023
@simonmichael simonmichael marked this pull request as ready for review August 31, 2023 05:08
@simonmichael
Copy link
Owner Author

simonmichael commented Aug 31, 2023

Notes on print behaviour:

print shows up to four amounts per posting:
amt - the posting amount
cost - the posting amount's cost
bal - the balance assertion amount
balcost - the balance assertion amount's cost

hledger's amount display styling can be divided into:
basic - everything except precision
prec - precision (number of decimal places)

print's styling behaviour over time:

|         | basic styling                | precision styling            |
| hledger | amt  | cost | bal  | balcost | amt  | cost | bal  | balcost |
| 1.14    | Y    | N    | N    | N       | Y    | N    | N    | N       |
| 1.15    | Y    | N    | N    | N       | Y    | N    | Y    | N       |
| 1.21    | Y    | N    | Y    | N       | Y*   | N    | N    | N       |
| 1.30    | Y    | Y    | Y    | N       | Y*   | N    | N    | N       |
| 1.31    | Y    | Y    | Y    | Y       | N    | N    | N    | N       |

* these add trailing decimal zeros.

@simonmichael simonmichael merged commit 29ff546 into master Sep 2, 2023
1 check passed
@simonmichael simonmichael deleted the 2023-08-print-style branch September 2, 2023 05:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-WISH Some kind of improvement request, hare-brained proposal, or plea. print
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant