haskell/ghcup-hs

Introduce pager mode (for `ghcup list`)

hasufell opened this issue · 0 comments

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: