Skip to content

Pager should not be used for empty output #6400

Description

@mgabeler-lee-6rs

Describe the bug

I have PAGER set in my environment to tell various tools my preferred pager. Every tool I use that understands this variable, except gh, understands that output smaller than a single terminal window doesn't need to go through the pager. With gh, it seems the only options are to run everything through a pager, or nothing. Including empty output!

This is annoying and frustrating.

gh version 2.17.0 (2022-10-04)

Steps to reproduce the behavior

  1. Create or find a repo with zero open PRs
  2. Clone this repo
  3. export PAGER=less
  4. Within the clone, run gh pr list
  5. Laugh/cry at less being opened to display byte 0/0 (END)
  6. Note also that gh did produce some output ... that it didn't send to the pager, but which is hidden due to the presence of the pager, until you quit it: no open pull requests in owner/reponame
  7. export GH_PAGER= to make this stop
  8. Cry that now no pager is used even for voluminous output 😢

Expected vs actual behavior

I expect gh to use the configure pager only when there is enough output to merit pagination, like every other tool that supports such config. Compare especially git

Logs

N/A

Activity

  1. LangLangBart commented on Oct 7, 2022

    @LangLangBart

    could perhaps be solved on the user side with an additional flag in the less command, e.g. -F/--quit-if-one-screen.

    ❯ less --version | head -1
    less 608 (PCRE2 regular expressions)
    
    
    ❯ man less | grep -A 3 'quit-if-one-screen'
           -F or --quit-if-one-screen
                  Causes less to automatically exit if the entire file can be dis-
                  played on the first screen.
  2. mgabeler-lee-6rs commented on Oct 7, 2022

    @mgabeler-lee-6rs
    ContributorAuthor

    Aah, yeah, and gh tries to set that for common cases via the LESS environment variable:

    if _, ok := os.LookupEnv("LESS"); !ok {
    pagerEnv = append(pagerEnv, "LESS=FRX")
    }

    but I have a more .. complex $LESS already set without -F (so that if I explicitly do foo | less, I'm sure to get less invoked)

    The gh config or GH_PAGER="less -F" works as a workaround 👍

  3. LangLangBart commented on Oct 9, 2022

    @LangLangBart

    Just for clarification for any maintainer.

    I also set the environment variable LESS without the flag -F, therefore I get Byte 0/0 (END) as seen in the GIF.

    # .zshrc
    # <--------- Less---------- >
    # from https://github.com/nablaa/dotfiles/blob/master/.zsh/environment.zsh
    # R - Raw color codes in output (don't remove color codes)
    # K - quit less immediately with ^C
    # q - be more quiet
    # M - Long prompts ("Line X of Y")
    # ~ - Don't show those weird ~ symbols on lines after EOF
    # g - Highlight results when searching with slash key (/)
    # I - Case insensitive search
    # s - Squeeze empty lines to one
    # w - Highlight first line after PgDn
    export LESS="-RKqM~gIsw"
    
    # Less Colors for Man Pages
    export LESS_TERMCAP_mb=$'\E[01;31m'      # begin blinking
    export LESS_TERMCAP_md=$'\E[01;38;5;74m' # begin bold
    export LESS_TERMCAP_me=$'\E[0m'          # end mode
    export LESS_TERMCAP_se=$'\E[0m'          # end standout-mode
    export LESS_TERMCAP_so=$'\E[01;31m'      # begin standout-mode - info box
    export LESS_TERMCAP_ue=$'\E[0m'          # end underline
    export LESS_TERMCAP_us=$'\E[01;32m'      # begin underline
    # disable the creation of the ~/.lesshst file
    export LESSHISTFILE=-

    I guess the issue can be closed ?

  4. mislav commented on Oct 10, 2022

    @mislav
    Contributor

    Thanks for the discussion so far!

    Every tool I use that understands this variable, except gh, understands that output smaller than a single terminal window doesn't need to go through the pager.

    Here is git CLI piping output definitely smaller than my terminal window through the configured pager:

    It is not the responsibility of the tool itself to determine your viewport size and how to handle pagination. Instead, that is the responsibility of the pager utility itself. Thus, gh will always start a pager for any amount of output. But, you are right that starting a pager for no output whatsoever is not really great user experience. Let's fix that!

    In the meantime please use the already discovered workaround by setting the LESS=FRX environment variable or GH_PAGER=less -FRX.

  5. added
    priority-3Affects a small number of users or is largely cosmetic
    and removed on Oct 10, 2022
  6. changed the title [-]Pager should be used only when output doesn't fit on screen[/-] [+]Pager should not be used for empty output[/+] on Oct 10, 2022
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 workinghelp wantedContributions welcomepriority-3Affects a small number of users or is largely cosmetic

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions