termutil

package
v0.0.0-...-9d3c4bc Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2019 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ClearSignal

func ClearSignal()

Arrange so that future Printer.Ok() calls will return Ok(). Note that if the process receives SIGINT in a future, Printer.Ok() becomes false.

func InstallSignalHandler

func InstallSignalHandler()

InstallSignalHandler sets up the process to catch SIGINT signals. All the standard Printer objects will report !Ok() after a SIGINT.

func WithCancel

func WithCancel(bg context.Context) (context.Context, context.CancelFunc)

WithCancel creates a context.Context object that reports cancellation when the user presses ^C. The caller must run the returned cancelfunc after use, or the context will leak.

REQUIRES: bg must not have deadline or report cancellation on its own.

Types

type BufferPrinter

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

BufferPrinter is a non-interactive printer that prints to an in-memory buffer without paging. Functions Bytes() and String() will retrieve the buffer contents.

func NewBufferPrinter

func NewBufferPrinter() *BufferPrinter

NewBufferPrinter creates a new, empty BufferPrinter.

func (*BufferPrinter) Close

func (p *BufferPrinter) Close()

Close implements Printer.

func (*BufferPrinter) Len

func (p *BufferPrinter) Len() int

Len returns the number of accumulated bytes; Len() == len(String()).

func (*BufferPrinter) Ok

func (p *BufferPrinter) Ok() bool

Ok implements Printer.

func (*BufferPrinter) Reset

func (p *BufferPrinter) Reset()

Reset clears the status of the printer.

func (*BufferPrinter) ScreenSize

func (p *BufferPrinter) ScreenSize() (int, int)

ScreenSize implements Printer.

func (*BufferPrinter) String

func (p *BufferPrinter) String() string

String yields the data written via Write and WriteString. It is idempotent.

func (*BufferPrinter) Write

func (p *BufferPrinter) Write(data []byte) (int, error)

Write implements Printer.

func (*BufferPrinter) WriteFloat

func (p *BufferPrinter) WriteFloat(v float64)

WriteFloat implements Printer.

func (*BufferPrinter) WriteInt

func (p *BufferPrinter) WriteInt(v int64)

WriteInt implements Printer.

func (*BufferPrinter) WriteString

func (p *BufferPrinter) WriteString(data string)

WriteString implements Printer.

func (*BufferPrinter) WriteTable

func (p *BufferPrinter) WriteTable(rowCallback func() ([]Column, error))

type Column

type Column struct {
	Name  symbol.ID
	Value string
}

type Printer

type Printer interface {
	// Write writes the given text data to the output. The implementation may ask
	// for "continue y/n?" in the middle when the data is long.
	Write(data []byte) (int, error)

	// WriteString is similar to Write(), but it takes a string.
	WriteString(data string)
	// WriteInt writes the value in decimal. It is equivalent to WriteString(fmt.Printf("%v", v))
	WriteInt(v int64)
	// WriteFloat writes the value in dotted decimal. It is equivalent to
	// WriteString(fmt.Printf("%v", v))
	WriteFloat(v float64)
	// WriteTable writes a table. rowCallback will be called repeatedly to
	// retrieve rows in the table.
	WriteTable(rowCallback func() ([]Column, error))

	// Ok() becomes false if the user answers 'N' to a 'continue y/n?' prompt.  Once
	// Ok() returns false, all future Ok() calls will return false, and Write and
	// WriteString become no-ops.
	Ok() bool

	// ScreenSize returns the screen (width, height), as # of characters.
	ScreenSize() (int, int)

	// Close closes the printer and releases its resources.
	Close()
}

Printer is an interface for paging long outputs for an interactive shell. It is a superset of io.Writer.

func NewBatchPrinter

func NewBatchPrinter(out io.Writer) Printer

NewBatchPrinter creates a Printer that writes to the given output non-interactively, without any paging.

func NewFilePrinter

func NewFilePrinter(path string, append bool) (Printer, error)

NewFilePrinter creates a Printer that writes to a file. If append==true, it appends contents to the file if the file already exists.

func NewHTMLPrinter

func NewHTMLPrinter(out io.Writer, maxTableCells int) Printer

NewHTMLPrinter creates a new Printer that writes contents in an HTML format.

func NewPipePrinter

func NewPipePrinter(name string, arg ...string) (Printer, error)

NewFilePrinter creates a Printer that sends data to a new process. Arg name is the name or path of the process, and args are the arguments to the process. They are passed to exec.Command.

func NewTerminalPrinter

func NewTerminalPrinter(out io.Writer) Printer

NewTerminalPrinter creates a Printer that performs paging ("continue y/n?"). Arg "out" is usually os.Stdout.

Jump to

Keyboard shortcuts

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