termui

package module
v0.0.0-...-7bc1492 Latest Latest
Warning

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

Go to latest
Published: Jan 22, 2018 License: Apache-2.0 Imports: 8 Imported by: 26

README

termui

termui - Utilities dealing with terminal interaction

Documentation

Overview

Package termui is a wrapper to enable disabling input echo and other terminal handling.

Index

Constants

View Source
const (
	// CodeUnknownError is a generic error code for errors without one
	CodeUnknownError = iota + 1
)

Variables

This section is empty.

Functions

func Decolorize

func Decolorize(message string) string

Decolorize is a function that strips out all colorizing control bytes

func HeaderColor

func HeaderColor(s string) string

HeaderColor is the default header color for tables

func PrintAndExit

func PrintAndExit(ui *UI, err error)

PrintAndExit prints the error to the ui and exits the program.

func PrintWarning

func PrintWarning(ui *UI, err error)

PrintWarning to the ui.

func TableContentHeaderColor

func TableContentHeaderColor(s string) string

TableContentHeaderColor is the default header content color for tables

Types

type Error

type Error interface {
	error
	Code() int
}

Error objects support having an error code in addition to the message

type ErrorPrinter

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

ErrorPrinter can be used to stop repetitive calls to the global like calls which all take a terminal.UI

func NewErrorPrinter

func NewErrorPrinter(ui *UI) *ErrorPrinter

NewErrorPrinter returns an error printer.

func (ErrorPrinter) PrintAndExit

func (e ErrorPrinter) PrintAndExit(err error)

PrintAndExit prints the error to the UI and exits.

func (ErrorPrinter) PrintWarning

func (e ErrorPrinter) PrintWarning(err error)

PrintWarning prints the error as a warning.

type Table

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

Table remembers headers, added rows, column widths, and a number of other things and later formats and prints these things.

func NewTable

func NewTable(headers ...string) *Table

NewTable is the constructor function creating a new printable table from a list of headers. The table is also connected to a UI, which is where it will print itself to on demand.

func (*Table) Add

func (t *Table) Add(row ...string)

Add extends the table by another row.

func (*Table) NoHeaders

func (t *Table) NoHeaders()

NoHeaders disables the printing of the header row for the specified table.

func (*Table) PrintTo

func (t *Table) PrintTo(result io.Writer)

PrintTo is the core functionality for printing the table, placing the formatted table into the writer given to it as argument. The exported Print() is just a wrapper around this which redirects the result into CF datastructures.

func (*Table) SetTransformer

func (t *Table) SetTransformer(columnIndex int, tr Transformer)

SetTransformer specifies a string transformer to apply to the content of the given column in the specified table.

func (*Table) Transform

func (t *Table) Transform(column int, s string) string

This Transform makes a PrintableTable an implementation of rowTransformer. It performs the per-column transformation for table content, as specified during construction and/or overridden by the user of the table, see SetTransformer.

type Transformer

type Transformer func(s string) string

Transformer is the type of functions used to modify the content of a table cell for actual display. For multi-line content of a cell the transformation is applied to each individual line.

type UI

type UI struct {
	io.Reader
	io.Writer
	PasswordReader termpassword.Reader
}

UI is an abstraction around a terminal with various helper functions to write to it.

func New

func New(input io.Reader, output io.Writer, passReader termpassword.Reader) *UI

New creates a terminal UI which writes to output, reads from input and can be used to read passwords safely.

func (*UI) Print

func (u *UI) Print(args ...interface{}) (int, error)

Print mirrors stdlib fmt.Print.

func (*UI) Printf

func (u *UI) Printf(format string, args ...interface{}) (int, error)

Printf mirrors stdlib fmt.Printf.

func (*UI) Println

func (u *UI) Println(args ...interface{}) (int, error)

Println mirrors stdlib fmt.Println.

func (*UI) Prompt

func (u *UI) Prompt(promptText string, args ...interface{}) string

Prompt the user for a line of input.

func (*UI) PromptDefault

func (u *UI) PromptDefault(promptText, defaultValue string, args ...interface{}) string

PromptDefault gets a line of input and provides a default if nothing is given.

Directories

Path Synopsis
Package sigint provides a Handler that calls exit handlers when the process has been interrupted by sigint (a ctrl-c typically).
Package sigint provides a Handler that calls exit handlers when the process has been interrupted by sigint (a ctrl-c typically).
fakes
Package fakes is was generated by counterfeiter.
Package fakes is was generated by counterfeiter.

Jump to

Keyboard shortcuts

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