Documentation ¶
Index ¶
- func ClearSignal()
- func InstallSignalHandler()
- func WithCancel(bg context.Context) (context.Context, context.CancelFunc)
- type BufferPrinter
- func (p *BufferPrinter) Close()
- func (p *BufferPrinter) Len() int
- func (p *BufferPrinter) Ok() bool
- func (p *BufferPrinter) Reset()
- func (p *BufferPrinter) ScreenSize() (int, int)
- func (p *BufferPrinter) String() string
- func (p *BufferPrinter) Write(data []byte) (int, error)
- func (p *BufferPrinter) WriteFloat(v float64)
- func (p *BufferPrinter) WriteInt(v int64)
- func (p *BufferPrinter) WriteString(data string)
- func (p *BufferPrinter) WriteTable(rowCallback func() ([]Column, error))
- type Column
- type Printer
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 ¶
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) Len ¶
func (p *BufferPrinter) Len() int
Len returns the number of accumulated bytes; Len() == len(String()).
func (*BufferPrinter) Reset ¶
func (p *BufferPrinter) Reset()
Reset clears the status of the printer.
func (*BufferPrinter) ScreenSize ¶
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) 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 ¶
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 ¶
NewBatchPrinter creates a Printer that writes to the given output non-interactively, without any paging.
func NewFilePrinter ¶
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 ¶
NewHTMLPrinter creates a new Printer that writes contents in an HTML format.
func NewPipePrinter ¶
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 ¶
NewTerminalPrinter creates a Printer that performs paging ("continue y/n?"). Arg "out" is usually os.Stdout.