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

Introduce pager mode (for ghcup list) #1118

Open
hasufell opened this issue Aug 12, 2024 · 0 comments
Open

Introduce pager mode (for ghcup list) #1118

hasufell opened this issue Aug 12, 2024 · 0 comments

Comments

@hasufell
Copy link
Member

hasufell commented Aug 12, 2024

Following #1115 it appears the list is now big enough that it can be annoying to handle. Although users can just issue ghcup list | less, other tools such as git by default open a pager, unless the output is part of a pipe.

So I'm proposing the following behavior:

  • new config option pager: { list: bool, cmd: string }
    • cmd is optional and can point to a full path or a filename (to be searched for in PATH)
    • when pager: nil -> paging disabled
    • when pager: { list: false, ... } -> paging disabled for list
    • pager: true is a shorthand for pager: { list: true } turning all boolean options true (if there are future ones)
    • pager: string is a shorthand for pager: { list: true, cmd: string }, turning all boolean options true (if there are future ones)
    • setting cmd to an empty string will disable paging as well
  • new cli option ghcup [-p|--paginate|-P|--no-pager]
    • overwrites config options
  • lookup of pager in the given order
    • if cmd for pager config option is set, use it
    • otherwise check $GHCUP_PAGER env var
    • otherwise check $PAGER env var
    • otherwise check the following binaries in order
      • most
      • more
      • less
  • when to open the pager
    • default is off
    • if paging is enabled through pager config option
    • or if paging is enabled through cli option
  • when to not open pager (overwrites all other conditions)
    • if ghcup is run as part of a pipe (e.g. ghcup list | grep foo or bar=$(ghcup list))
    • or if ghcup list --raw-format is passed
    • or if no valid pager is found
  • other remarks
    • warnings or anything else going to stderr is not shown in the pager
    • we may want pager for ghcup --help (compare with git --help vs git -h)
    • setting pager to cat should work too (and just print to stdout)

In the future we may:

  1. switch the default for paging to true (need community input)
  2. but only invoke a pager when the terminal height is less than the output (compare with less -F)

Useful libraries to check:

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

No branches or pull requests

1 participant