Skip to content

gh api not using $PAGER correctly #9017

Description

@jwodder

OS: macOS Sonoma 14.4.1
gh version: 2.48.0 (installed via Homebrew)

I have the environment variables PAGER=/usr/bin/less and LESS=-iRS (but not GH_PAGER) set in my shell. Starting sometime maybe in the last month, whenever I run gh api without any output redirection, the program will start less to show the output, but the screen will show the last lines of the output rather than the start of the output, and if I then press any key, the output disappears, to be replaced by a tilde on each line (which is how less displays empty input). I think this problem is caused by mixing up stdout and stderr, but I'm unable to come up with an MVCE.

If I unset PAGER, gh api will output to stdout correctly. If I unset LESS instead, gh api still outputs to stdout without invoking less.

Activity

  1. williammartin commented on Apr 28, 2024

    @williammartin
    Member

    Uh oh! Any chance you could capture this in a screen recording to help me better understand what you're seeing! It would be very interesting to know if this reproduced in v2.47.0, v2.46.0 and v2.45.0 if you're up for doing some spelunking! How often does it reproduce?

  2. jwodder commented on Apr 28, 2024

    @jwodder
    Author

    @williammartin

    Any chance you could capture this in a screen recording to help me better understand what you're seeing!

    Here are two asciinema recordings; the first one involves more than a screenful of output, while the second involves less than a screenful. In both cases, all I did inside less was press g (which should have taken me to the top of the output but instead cleared the output) and then q to quit.

    It would be very interesting to know if this reproduced in v2.47.0, v2.46.0 and v2.45.0 if you're up for doing some spelunking!

    I downloaded the macOS amd64 release assets for each of those versions from the Releases page, and none of them exhibited the bug. Just to be sure this wasn't Homebrew's fault, I also downloaded the 2.48.0 asset from the Releases page, and it still has the buggy behavior.

    How often does it reproduce?

    Every time I've used gh api for the past month or so (assuming PAGER and LESS are set and there's no output redirection etc.)

  3. babakks commented on Apr 28, 2024

    @babakks
    Member

    I'm not sure if this helps, but I cannot reproduce it on Ubuntu/Linux (i.e., gnome-terminal). This is what I get (note that GH_PAGER is not set):

    Recording 2024-04-28 at 18 58 01

  4. babakks commented on Apr 28, 2024

    @babakks
    Member

    UPDATE My bad. Actually, the above test was on an earlier version (v2.42.0), which was working as expected. But when I tried with the latest version, it failed (on v2.48.0):

    Recording 2024-04-28 at 19 03 50

  5. williammartin commented on Apr 28, 2024

    @williammartin
    Member

    @babakks if you're willing to build from source to check this out I would bet good money it was this PR: #8620

  6. babakks commented on Apr 28, 2024

    @babakks
    Member

    @williammartin I'm currently debugging this and trying both v2.47.0 and v2.48.0 to see what's causing this. So far, everything is the same between the two (for this specific scenario where the newly introduced jsonArrayWriter is not used). Will update you soon.

  7. babakks commented on Apr 29, 2024

    @babakks
    Member

    @williammartin I just submitted #9020 to fix this. The change that caused this in v2.48.0, was the calling of StartPager method at a later stage.

    And sorry because it's not yet marked as help-wanted. I thought this way it's easier for you to see the changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinggh-apirelating to the gh api commandneeds-triageneeds to be reviewed

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions