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

gh api not using $PAGER correctly #9017

Closed
jwodder opened this issue Apr 28, 2024 · 7 comments · Fixed by #9020
Closed

gh api not using $PAGER correctly #9017

jwodder opened this issue Apr 28, 2024 · 7 comments · Fixed by #9020
Labels
bug Something isn't working gh-api relating to the gh api command needs-triage needs to be reviewed

Comments

@jwodder
Copy link

jwodder commented Apr 28, 2024

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.

@jwodder jwodder added the bug Something isn't working label Apr 28, 2024
@cliAutomation cliAutomation added the needs-triage needs to be reviewed label Apr 28, 2024
@williammartin
Copy link
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?

@williammartin williammartin added the gh-api relating to the gh api command label Apr 28, 2024
@jwodder
Copy link
Author

jwodder commented Apr 28, 2024

@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.)

@babakks
Copy link
Contributor

babakks commented Apr 28, 2024

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

@babakks
Copy link
Contributor

babakks commented Apr 28, 2024

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

@williammartin
Copy link
Member

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

@babakks
Copy link
Contributor

babakks commented Apr 28, 2024

@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.

@babakks
Copy link
Contributor

babakks commented Apr 29, 2024

@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
Labels
bug Something isn't working gh-api relating to the gh api command needs-triage needs to be reviewed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants