Girocco/CLIUtil.pm: add setup_pager and setup_pager_stdout
commit0fec3dda35195b7f5e054ed1eb672d8864f86a33
authorKyle J. McKay <mackyle@gmail.com>
Fri, 12 Feb 2021 13:45:46 +0000 (12 06:45 -0700)
committerKyle J. McKay <mackyle@gmail.com>
Fri, 12 Feb 2021 13:45:46 +0000 (12 06:45 -0700)
tree74fb1f2fe939d6c8dcc055814f3874c6996716e6
parent1905f2331439f4e45ed365de4f16f13faec0149d
Girocco/CLIUtil.pm: add setup_pager and setup_pager_stdout

The setup_pager function returns a pipe to a pager as determined
by the PAGER environment variable or what can be found in $PATH.

The setup_pager_stdout redirects STDOUT to a pager depending
on the arguments passed in, by default (with no arguments), it
redirects STDOUT to a pager only if STDOUT is a terminal.

But, if a known pager is already in use (tested courtesy of the new
pager_in_use function), then setup_pager_stdout does nothing.
If setup_pager_stdout activates a pager, also set the appropriate
known environment variables to discourage nested pagers.

The setup_pager_stdout function does some "magic" to make things
just work from the point of view of the caller, but those things
are quite possibly unworkable on a non-unixen system.  But then
so too will likely be running Girocco on such a system.

Signed-off-by: Kyle J. McKay <mackyle@gmail.com>
Girocco/CLIUtil.pm