pager

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2026 License: MIT Imports: 9 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package pager pages long output through $PAGER (less by default) on capable terminals, and passes writers through untouched everywhere else (pipes, dumb terminals, missing pager).

Usage in a command with long output:

out, stop, err := pager.Start(ctx.Out)
if err != nil {
    return err
}
defer stop()
// ... write everything to out ...

Quitting the pager early breaks later writes with EPIPE; treat those as success with pager.Closed(err) instead of failing the command.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Closed

func Closed(err error) bool

Closed reports a broken downstream pipe: the pager (or piped reader) went away, typically because the user quit early. Treat as success, not failure.

func Start

func Start(w io.Writer, opts ...Option) (io.Writer, func(), error)

Start launches the pager for w when appropriate and returns the writer commands should use plus a stop func (close the feed, wait for exit). Paging needs a terminal file, a non-dumb TERM, and a found pager binary; otherwise it returns w and a no-op stop with no error.

Types

type Option

type Option func(*options)

Option tunes Start.

func WithPager

func WithPager(cmd string) Option

WithPager forces a pager command line, e.g. "less -R" or "more". Default: $PAGER, then less.

Jump to

Keyboard shortcuts

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