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

Pager ignores local encoding #2275

Open
thielema opened this issue Oct 23, 2024 · 2 comments
Open

Pager ignores local encoding #2275

thielema opened this issue Oct 23, 2024 · 2 comments
Labels
A-BUG Something wrong, confusing or sub-standard in the software, docs, or user experience. cli Command line parsing, options, arguments and suchlike. i18n Internationalisation/localisation-related.

Comments

@thielema
Copy link
Contributor

The following applies to hledger/HEAD (fa3676d).

I have a journal encoded in Latin-1. I can watch it like so:

$ iconv -f latin1 hledger-journal
~ monthly from 2024-01-01  Periodic
    Forderung   42 Euro
    Erlös

2024-01-01 Bla
    Bank  23 Euro
    Forderung

Please note the umlaut "ö" in "Erlös".

Now, for short outputs the local encoding is respected, for long output is encoded in UTF-8, even if written to a file.

$ LANG=de_DE hledger print -f hledger-journal -e 2024-02-10 --forecast >hledger-journal-printed 
$ iconv -f latin1 hledger-journal-printed
2024-01-01 Bla
    Bank              23 Euro
    Forderung

2024-02-01 Periodic
    Forderung         42 Euro
    Erlös

This is the expected result. LANG=de_DE switches to Latin-1 encoding for this one run of hledger.

Now a longer output:

$ LANG=de_DE hledger print -f hledger-journal -e 2024-10-10 --forecast >hledger-journal-printed 
$ iconv -f latin1 hledger-journal-printed
2024-01-01 Bla
    Bank              23 Euro
    Forderung

2024-02-01 Periodic
    Forderung         42 Euro
    Erlös

2024-03-01 Periodic
    Forderung         42 Euro
    Erlös

...

I think it is not a good idea to have different encodings depending on the output length. For piping to a file there should not be a pager involved, at all.

My preferred solution would be to always use the local encoding, as it was the case until now.

@simonmichael
Copy link
Owner

That’s certainly surprising behaviour. Thanks for the report.

Since enabling this feature I’ve documented the logic in runPager. It’s probably still too weak at detecting when to use a pager (compared to our ansi colour detection, eg, which is aware of pipes).

There might also be a problem with loss of encoding when legitimately using a pager, it sounds like.

@simonmichael simonmichael added A-BUG Something wrong, confusing or sub-standard in the software, docs, or user experience. i18n Internationalisation/localisation-related. cli Command line parsing, options, arguments and suchlike. labels Oct 24, 2024
@simonmichael
Copy link
Owner

simonmichael commented Dec 21, 2024

Would you mind retesting this when you get a chance ? The pager code was rewritten since.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-BUG Something wrong, confusing or sub-standard in the software, docs, or user experience. cli Command line parsing, options, arguments and suchlike. i18n Internationalisation/localisation-related.
Projects
None yet
Development

No branches or pull requests

2 participants