Printing to stdout

63 views
Skip to first unread message

Bob Wilson

unread,
Jun 9, 2023, 3:39:35 PM6/9/23
to Ledger
Hi folks,
   I recently upgraded to Ledger 3.3.2-20230330, from 3.2.1-20200518.

Previously, running a command like `ledger -f ledger.dat balance ^Assets` would print results directly to the screen and return me to the prompt, but now that same command prints results to some kind of temporary screen that disappears when I hit `q`. It's like the difference between `cat` and `less`. Sorry I don't know the right terminology!

As a workaround, I can pipe the command into cat, and then it prints to the screen. Is there a way to just print to the screen by default?

Thanks!
Bob Wilson

John Wiegley

unread,
Jun 10, 2023, 2:36:04 AM6/10/23
to Bob Wilson, Ledger
>>>>> "BW" == Bob Wilson <mills...@gmail.com> writes:

BW> Previously, running a command like `ledger -f ledger.dat balance ^ Assets`
BW> would print results directly to the screen and return me to the prompt,
BW> but now that same command prints results to some kind of temporary screen
BW> that disappears when I hit `q`. It's like the difference between `cat` and
BW> `less`. Sorry I don't know the right terminology!

Can you try with the --no-pager option? I’m not sure why the default behavior
would have changed, though…

John

Bob Wilson

unread,
Jun 10, 2023, 12:57:10 PM6/10/23
to Ledger
--no-pager works. Terminology in hand, the guide suggested looking at the LEDGER_PAGER environment variable, which is unset on my platform.

I installed via homebrew (I'm on macos 13.4). Perhaps some detail on how they compiled ledger is relevant?

John Wiegley

unread,
Jun 10, 2023, 3:36:09 PM6/10/23
to Bob Wilson, Ledger, Martin Michlmayr
>>>>> "BW" == Bob Wilson <mills...@gmail.com> writes:

BW> --no-pager works. Terminology in hand, the guide suggested looking at the
BW> LEDGER_PAGER environment variable, which is unset on my platform.

BW> I installed via homebrew (I'm on macos 13.4). Perhaps some detail on how
BW> they compiled ledger is relevant?

It looks like this may have broken in commit
21280a9da3ca6ed70a10f95e1ef0717d5f65ee99:

commit 21280a9da3ca6ed70a10f95e1ef0717d5f65ee99
Author: Martin Michlmayr <t...@cyrius.com>
Date: Tue Jun 16 13:17:53 2020 +0800

Use PAGER when environment variable is set

The code looked for "less" if $PAGER is not set, but it didn't
actually use $PAGER when it it defined.

Fixes #1674

Nothing else since that earlier release date has changed the PAGER logic.

John

Alexis

unread,
Jun 11, 2023, 2:46:46 AM6/11/23
to John Wiegley, Ledger, Martin Michlmayr, Bob Wilson
Thanks John for providing support and thanks for raising this issue Bob.
Looking at the code there are few questions that arise for me:

* Should ledger really be looking for and use less if PAGER is unset?
Isn't the absence of PAGER and indicator that the user prefers their
output straight to the terminal?

* When looking for less shouldn't ledger search all directories in PATH
instead of hard-coded locations?
If yes, does anyone know of a UNIX PATH searching function readily
available, e.g. in the Boost Filesystem Library¹ before a custom
one is added?

* Where and how is LEDGER_PAGER used in the source code?
A quick grep for LEDGER_PAGER did not

Is there some generic code that allows any ledger command-line option
to be used as an upper-cased and LEDGER_-prefix environment variable?
If yes, where is it implemented?

* How could this be tested along with other unit tests, so that
once a desired behaviour is defined its implementation is tested.


Alexis

¹ https://www.boost.org/doc/libs/1_82_0/libs/filesystem/doc/index.htm

John Wiegley

unread,
Jun 11, 2023, 11:29:57 PM6/11/23
to Ledger, Martin Michlmayr, Bob Wilson
>>>>> Alexis <surr...@gmail.com> writes:

> * Should ledger really be looking for and use less if PAGER is unset? Isn't
> the absence of PAGER and indicator that the user prefers their output
> straight to the terminal?

I don’t think it should. If PAGER is not set, it shouldn’t use a pager…

> * When looking for less shouldn't ledger search all directories in PATH
> instead of hard-coded locations? If yes, does anyone know of a UNIX PATH
> searching function readily available, e.g. in the Boost Filesystem Library¹
> before a custom one is added?

Yes, searching PATH is The Right Way.

> * Where and how is LEDGER_PAGER used in the source code?
> A quick grep for LEDGER_PAGER did not

> Is there some generic code that allows any ledger command-line option
> to be used as an upper-cased and LEDGER_-prefix environment variable?
> If yes, where is it implemented?

Yes, the code to do so begins here:

https://github.com/ledger/ledger/blob/master/src/global.cc#L394

> * How could this be tested along with other unit tests, so that once a
> desired behaviour is defined its implementation is tested.

You could use a pager that ignores everything and just outputs “I was used”,
and then set the test expectation to that value?

John
Reply all
Reply to author
Forward
0 new messages