pager

package
v0.0.0-...-c3759fd Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2023 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package pager implements paging using commands "less" or "more", depending on availability.

A writer that wraps long text lines to a specified length.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Get

func Get(err error) (int, bool)

Get returns the process process exit return code given an error returned by exec.Cmd's Wait or Run methods. If no exit code is present, Get will return false.

func Main

func Main(ctx context.Context, fn func(ctx context.Context, out io.WriteCloser) int) int

Main implements paging using commands "less" or "more" if they are available. If os.Stdout is not terminal or less/more are not available in $PATH, Main calls fn with out set to os.Stdout and returns its exit code. Otherwise creates a pager subprocess, directs its stdout to os.Stdout and calls fn with out set to pager stdin. fn's context is canceled if the user quits pager.

If fn returns non-zero exit code before pager exits, Main returns that exit code. Otherwise Main returns pager's exit code. It is a race between the user hitting q and fn failing.

Example:

func main() int {
	return Main(context.Background(), func(ctx context.Context, out io.WriteCloser) int {
		for i := 0; i < 100000 && ctx.Err() == nil; i++ {
			fmt.Fprintln(out, i)
		}
		return 0
	})
}

func New

func New(w io.Writer, sep string, l int) io.Writer

Returns a writer that splits its input into multiple parts that have the same length and adds a separator between these parts.

func NewRFC822

func NewRFC822(w io.Writer) io.Writer

Creates a RFC822 text wrapper. It adds a CRLF (ie. \r\n) each 76 characters.

Types

This section is empty.

Jump to

Keyboard shortcuts

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