This allows using the special string `%account` in auto posting rules.
When run, this will be substituted with the account name of the matched
posting.
This adds a safer version of spanDefaultsFrom that won't create spans
that end before they start, and updates all reports to use it.
The only related change noticed so far is that close now gives an
error instead of a malformed entry, when there's no data to close.
[#2409]
This broke in 1.43.
Now we ignore any IOException whose message contains "broken pipe".
Hopefully this matches pre-1.43 behaviour and doesn't hide real errors.
This upgrades Account to enable it to store a multiperiod balance, with
a separate balance for each date period. This enables it do the hard
work in MultiBalanceReport.
Some new types are created to enable convenient operation of accounts.
- `BalanceData` is a type which stores an exclusive balance, inclusive
balance, and number of postings. This was previously directly stored
in Account, but is now factored into a separate data type.
- `PeriodData` is a container which stores date-indexed data, as well as
pre-period data. In post cases, this represents the report spans,
along with the historical data.
- Account becomes polymorphic, allowing customisation of the type of
data it stores. This will usually be `BalanceData`, but in
`BudgetReport` it can use `These BalanceData BalanceData` to store
both actuals and budgets in the same structure. The data structure
changes to contain a `PeriodData`, allowing multiperiod accounts.
Some minor changes are made to behaviour for consistency:
- --declared treats parent accounts consistently.
- --flat --empty ensures that implied accounts with no postings are not displayed, but
accounts with zero balance and actual postings are.
This and/or the previous related change also changed a few cases which
always traced or always logged; now all debug output is consistently
either traced or logged.
A very long-awaited improvement: for unicode exceptions, and I/O
exceptions which look like they were caused by a unicode error
(usually text decoding failure), our error message now includes
an explanation and advice on what to do.
Currently this uses the GHC.IO.Encoding API, which is not ideal:
"The API of this module is unstable and not meant to be consumed by
the general public. If you absolutely must depend on it, make sure to
use a tight upper bound, e.g., base < 4.X rather than base < 5,
because the interface can change rapidly without much warning."
Also it relies on scanning for patterns in GHC's various
unicode-related error messages, which may not be complete and could
change in future. To do: try the encoding package's IO helpers,
perhaps they give more specific exceptions.
- Added support for unseparated dates, for convenience in ghci and for parseHledgerVersion
- Noted two user-facing uses: --value's argument, and import's .latest files.
YYYYMMDD dates will now also work there. Left this undocumented.
- Noted this is now more permissive, parsing many integers successfully; not expecting problems.
These now call error' and show errors in the standard style:
- reading a nonexistent data file
- reading an unsafe dotted file name on windows
- web: using --socket on windows
- demo: demo not found
- demo: error while running asciinema
- diff: bad arguments
- print --match: no match found
- register --match: no match found
- roi: no investment transactions found
Hledger.Utils.IO helpers have been updated and new ones have been
added (exitOnExceptions, exitWithError) to allow consistent display of
program errors whether compiled with GHC <9.10, GHC 9.10, or GHC >9.10.
The trailing newlines added by GHC 9.10 are gone,
and so is the "uncaught exception" output added by GHC 9.12.
We now support having multiple sessions clocked in. These are paired by
account name if given on the out entry, and otherwise an out closes the
most recent in entry.
Note that this breaks some backwards compatibility, in that we
previously ignored the description on the clock out entry. To mitigate
this, a new hidden flag --timeclock-old has been added, which reverts to
the old behavior.
Previously our cabal files used cabal-version 1.12, and were in theory
buildable with any ancient version of cabal. Now at least cabal 2.2
(or a version of stack built with with similar Cabal version) is
required to build hledger.
"-" implies data from standard input so "string" is perhaps more
correct, but I think this is a harmless simplification and it
makes `files` output consistent when run by `run`.
`If blocks` and `If tables` now allow multiple matchers on the same line
separated by `&&` (AND) or `&& !` (AND NOT).
Example `if block` with two matchers on the same line:
if %description amazon && %date 2025-02-22
account2 expenses:books
Example `if table` with two matchers on the same line:
if,account2
%description amazon && %date 2025-02-22, expenses:books
On some systems, TERM is set to a value that doesn't have a valid
terminfo entry. Rather than hackily fall back on a value for TERM that
appears to work in most contexts (TERM=dumb) but which isn't guaranteed
anywhere to be valid, use proper POSIX ioctls to get the tty width.
This has the added bonus of also working on Windows.
In fact, we already settled on computing the terminal size in this way
in hledger-lib, so this commit centralizes the choice of the logic
there.
Also added a note for alternative methods and their tradeoffs, in case
this turns out to be fragile on some systems.
When running `cd hledger-lib && ghci test/unittest.hs`, ghci complains
with:
```
test/unittest.hs:7:1: error:
Could not find module ‘Hledger’
It is not a module in the current program, or in any known package.
|
7 | import "hledger-lib" Hledger (tests_Hledger)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Failed, no modules loaded.
```
This commit removes the "hledger-lib" package-qualified import, such
that above ghci command works as expected.
However, there is a comment in hledger-lib/test/unittest.hs that says:
> package-qualified import to avoid cabal missing-home-modules warning
> (and double-building ?)
The missing-home-modules warning and the double building can indeed be
reproduced by running (after removing the "hledger-lib"
package-qualified import): `cd hledger-lib && cabal build unittest`. It
will first build `hledger-lib`, then show a warning about
missing-home-modules, and then build `hledger-lib` again.
After comparing the unittest sections of hledger.cabal and
hledger-lib.cabal, the solution turned out to be to remove `./` from
hs-source-dirs for unittest. Don't ask me why though!
Overall it's a nice cleanup.
Previously, hledger could read CSV files containing non-ascii
characters only if they are UTF8-encoded. Now there is a new CSV
rule, encoding ENCODING, which allows reading CSV files with other
encodings.
This adds a dependency on the encoding library, which supports fewer
encodings than text-icu but does not require a third-party C library.
To avoid build issues on various platforms, we require version 0.10+.
This adds some use of the ImplicitParams language extension, required
by encoding's API, but only in a small code region.
This also changes the type of Reader's rReadFn; it now takes
a `Handle` rather than a `Text`, allowing more flexibility.
error' and usageError now redden and bolden the first line of error
messages, when ANSI codes are supported and permitted.
And warn goldens and boldens the first line of warning messages.
When print is generating beancount output, turn off the usual
inheritance of account tags by postings; it would generate excessive
metadata in the journal. Beancount can do or not do that kind of
inheritance itself.
Transaction and posting tags (and posting tags inherited from accounts)
are now converted safely to Beancount-compatible transaction and posting
metadata lines.
Previously depth-limiting was universal across all accounts, e.g. all
accounts are clipped to depth 2. However, sometimes you want certain
accounts clipped to a different depth than others, e.g. all expenses to
depth 3, while all assets to depth 2. This commit enables depth-limiting
to optionally include a regular expression, which limits the accounts it
applies to.
More than one depth limit can be passed, and they are applied to each
account name by the following rules:
- If one or more regular-expression depth limit applies, use the
most specific one
- If no regular-expression depth limits apply, and a flat depth limit is
supplied, use that
- Otherwise, do not do any depth limiting
For example, this will clip all accounts matching "assets" to depth 3,
all accounts matching "expenses" to depth 2, and all other accounts to
depth 1.
--depth assets=3 --depth expenses=2 --depth 1
Market prices are now shown using one line each,
the known prices are listed (forward / forward+reverse),
and the status of --infer-market-prices is shown.
- These special hidden tags, used internally, have been renamed:
- `_modified` -> `_modified-transaction`
- `_cost-matched` -> `_cost-posting`
- `_conversion-matched` -> `_conversion-posting`
- All special hidden tags now have a similarly-named visible tag,
and `--verbose-tags` now shows those more often, which is useful
when troubleshooting `--infer-equity`, `--infer-costs`,
or the matching of redundant costs and conversion postings.
- The `generated-posting:` tag added by `--infer-equity` is now valueless.
- The `modified-transaction:` tag added by `--auto` now appears on its own line.
Unsupported chars are now hex-encoded, not just converted to dashes.
This helps keep account and commodity names unique, especially with
the equity conversion account names generated by --infer-equity when
using currency symbols.
(Those could also be converted to ISO 4217 codes, in theory, but
for now we just hex encode them, which is easier to make robust.)
Also, Beancount commodity symbols are no longer enclosed in
hledger-style double quotes.
Hledger.Utils.IO's ansi style/color helpers now respect --color=yes,
so that eg `hledger --color=yes | less -R` shows bold headings as
you'd expect.
Hledger.Utils.IO.rgb' now takes Float arguments instead of Word8.
When using `less` as pager, if HLEDGER_LESS is defined, it will
provide the options (instead of LESS + hledger's extra options).
You can set your own preferred options here, or you can set it
equal to LESS to use exactly those options.
[#2272]-related
Currently this sets a rather ambitious set of options,
and overrides the existing LESS:
--chop-long-lines
--hilite-unread
--ignore-case
--mouse
--no-init
--QUIT-AT-EOF
--quit-if-one-screen
--RAW-CONTROL-CHARS
--squeeze-blank-lines
--use-backslash
--use-color
This fixes the error displayed when quitting the pager with long output.
It also replaces the pager lib with more robust homegrown pager utilities,
which should prevent a number of failure modes.
The equity:conversion account, and its variations equity:trade(s) and equity:trading,
normally detected as V/Conversion type, now become ordinary E/Equity accounts
if some other account is declared as V/Conversion type.
This is motivated by the next commit, in which `check accounts` will
stop warning about conversion accounts and their subaccounts,
which means all of the above names and their subaccounts would remain
always exempt from strict account checking.
Now, if the user declares their own conversion account, those default
accounts will become controllable by account checking again.
Which at least reduces the allowlist a bit.
Hopefully this won't cause hassles.
Builds made with ghc 9.10+ and the 'debug' build flag, will show
(some kind of, partial) stack traces when the program ends with an
error. (And also will have ghc-debug support enabled.)
The stack traces will probably improve in due course.
--color now also works in a config file, like --pager, except for two
cases: it does not affect colouring of debug output, or the colouring
helpers used in the check recentassertions error message.