Merge pull request #2020 from tgyurci/gh-pager-env

Add support for GH_PAGER
This commit is contained in:
Nate Smith 2020-09-29 14:52:58 -05:00 committed by GitHub
commit 127d0b8717
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 2 deletions

View file

@ -28,7 +28,7 @@ func NewHelpTopic(topic string) *cobra.Command {
DEBUG: set to any value to enable verbose output to standard error. Include values "api"
or "oauth" to print detailed information about HTTP requests or authentication flow.
PAGER: a terminal paging program to send standard output to, e.g. "less".
GH_PAGER, PAGER (in order of precedence): a terminal paging program to send standard output to, e.g. "less".
GLAMOUR_STYLE: the style to use for rendering Markdown. See
https://github.com/charmbracelet/glamour#styles

View file

@ -248,6 +248,13 @@ func System() *IOStreams {
stdoutIsTTY := isTerminal(os.Stdout)
stderrIsTTY := isTerminal(os.Stderr)
var pagerCommand string
if ghPager, ghPagerExists := os.LookupEnv("GH_PAGER"); ghPagerExists {
pagerCommand = ghPager
} else {
pagerCommand = os.Getenv("PAGER")
}
io := &IOStreams{
In: os.Stdin,
originalOut: os.Stdout,
@ -255,7 +262,7 @@ func System() *IOStreams {
ErrOut: colorable.NewColorable(os.Stderr),
colorEnabled: EnvColorForced() || (!EnvColorDisabled() && stdoutIsTTY),
is256enabled: Is256ColorSupported(),
pagerCommand: os.Getenv("PAGER"),
pagerCommand: pagerCommand,
}
if stdoutIsTTY && stderrIsTTY {