pager

package module
v0.0.0-...-6d4a232 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 20, 2019 License: Apache-2.0 Imports: 7 Imported by: 1

Documentation

Overview

Package pager provides functions for setting up and tearing down a pager for the stdout and stderr of a Go program running in a unix-like environment. It includes the ability to detect non-tty outputs and dumb terminals, appropriately skipping opening a pager in such instances.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Close

func Close() error

Close closes the pager. This call will block until the pager is exited.

func Open

func Open() error

Open sets up the environment to be paged to a pager found on the system if the current stdout/stderr is a non-dumb terminal. It uses the value of the environment "PAGER" first. If that isn't set it attempts to use "pager", "less", and "more" in that order. If no suitable pager is found Open still returns without error but no pager is setup.

If stdout/stderr is a dumb terminal Open does nothing.

After a call to Open subsequent writes to os.Stdout and os.Stderr will be redirected to a pager.

Note that Close must be called after an open in order for the pager to be closed correctly. This should generally be done using a defer.

Example
package main

import (
	"fmt"

	"github.com/gerow/pager"
)

func main() {
	pager.Open()
	defer pager.Close()

	for i := 0; i < 10; i++ {
		fmt.Printf("%d hello from my pager!\n", i)
	}

}
Output:

0 hello from my pager!
1 hello from my pager!
2 hello from my pager!
3 hello from my pager!
4 hello from my pager!
5 hello from my pager!
6 hello from my pager!
7 hello from my pager!
8 hello from my pager!
9 hello from my pager!

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL