luci: Index | Files

package pager

import ""

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


Package Files


func Main Uses

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.


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

Package pager imports 8 packages (graph) and is imported by 2 packages. Updated 2020-12-06. Refresh now. Tools for package owners.