Introduce pager mode (for `ghcup list`)
hasufell opened this issue · 0 comments
hasufell commented
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 forpager: { list: true }
turning all boolean optionstrue
(if there are future ones)pager: string
is a shorthand forpager: { list: true, cmd: string }
, turning all boolean optionstrue
(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
forpager
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
- if
- 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
orbar=$(ghcup list)
) - or if
ghcup list --raw-format
is passed - or if no valid pager is found
- if ghcup is run as part of a pipe (e.g.
- other remarks
- warnings or anything else going to stderr is not shown in the pager
- we may want pager for
ghcup --help
(compare withgit --help
vsgit -h
) - setting pager to
cat
should work too (and just print to stdout)
In the future we may:
- switch the default for paging to
true
(need community input) - but only invoke a pager when the terminal height is less than the output (compare with
less -F
)
Useful libraries to check:
- https://hackage.haskell.org/package/terminal-size
- https://hackage.haskell.org/package/pager (I don't think I want to depend on this, but it can be an inspiration)