pager

package module
v0.0.0-...-d6350fd Latest Latest
Warning

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

Go to latest
Published: Jun 18, 2017 License: MIT Imports: 5 Imported by: 2

README

go-pager

GoDoc

go get snai.pe/go-pager

A Go library to help programs call and write to the user's pager.

The library introduces a Pager type that abstracts a pager program as an io.WriteCloser. It understands $PAGER in a way that is compliant with POSIX's man 1 man.

Documentation

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	ErrNoCommand = errors.New("No pager command to execute.")
	ErrClosed    = errors.New("The pager was closed.")
)

Functions

This section is empty.

Types

type Pager

type Pager struct {
	// contains filtered or unexported fields
}

Pager spawns and lets users write to a pager program.

If an error occurs while writing to the pager, all subsequent writes, Close, and Error, will return that error.

It implements io.WriteCloser.

func Open

func Open() (*Pager, error)

Open calls OpenPager("", nil).

Example
out, err := pager.Open()
if err != nil {
	log.Fatal(err)
}
defer out.Close()

out.Write([]byte("Hello, World!"))
Output:

Hello, World!

func OpenPager

func OpenPager(command string, dst io.Writer) (*Pager, error)

OpenPager spawns the pager program from the passed command, redirecting its standard output to dst, and returns a new Pager object.

If command is an empty string, then the value of the PAGER enviroment variable is used instead. If it is also empty, then ErrNoCommand is returned. Any command is valid as long as they are acceptable as an operand to "sh -c".

If dst is nil, os.Stdout is used instead.

func (*Pager) Close

func (p *Pager) Close() error

Close closes the write end of the pager and frees all ressources associated with it. It returns the last write error that occured, or any error from the pager process.

func (*Pager) Error

func (p *Pager) Error() error

Error returns the last error that occured during a write or Close.

func (*Pager) ReadFrom

func (p *Pager) ReadFrom(rd io.Reader) (n int64, err error)

ReadFrom implements io.ReaderFrom. It is equivalent to a call to io.Copy using the underlying write end of the pager as destination.

func (*Pager) Write

func (p *Pager) Write(data []byte) (n int, err error)

Write writes the contents of data into the pager, and returns the number of bytes written. If n < len(data), it also returns an error explaining why the write is short.

If Closed was previously called, or if the user closes the read end of the pager -- typically by exiting the pager program -- then Write returns the ErrClosed error.

Jump to

Keyboard shortcuts

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