Skip to content

Commit

Permalink
Improve PAGER usage. (grafana#38)
Browse files Browse the repository at this point in the history
* Improve PAGER usage.
- Don't paginate if content fits on one screen.
- Honor colors from less.

Signed-off-by: Tom Wilkie <tom.wilkie@gmail.com>
  • Loading branch information
tomwilkie authored and sh0rez committed Aug 12, 2019
1 parent 626b097 commit 39b00be
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions cmd/tk/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,17 @@ func pageln(i ...interface{}) {

// get system pager, fallback to `more`
pager := os.Getenv("PAGER")
var args []string
if pager == "" {
pager = "more"
// --raw-control-chars Honors colors from diff.
// --quit-if-one-screen Closer to the git experience.
// --no-init Don't clear the screen when exiting.
pager = "less"
args = []string{"--raw-control-chars", "--quit-if-one-screen", "--no-init"}
}

// invoke pager
cmd := exec.Command(pager)
cmd := exec.Command(pager, args...)
cmd.Stdin = strings.NewReader(fmt.Sprintln(i...))
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
Expand Down

0 comments on commit 39b00be

Please sign in to comment.