Documentation ¶
Overview ¶
Package opshell - Operator's interactive shell
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrOutputClosed = errors.New("output channel closed")
ErrOutputClosed is returned by Shell.Do when it returns because someone closed the output channel.
Functions ¶
func ColorEC ¶
func ColorEC(ec *term.EscapeCodes, color Color) []byte
ColorEC returns the escape code for the given color from ec. A non-nil slice will always be returned, even if ec is nil. As a special case, ColorNone returns an empty slice, as do unknown colors. The returned slice is a copy of the slice in ec or a newly-allocated slice; it may be modified at will.
Types ¶
type CLine ¶
type CLine struct { Color Color Line string Prompt string NoTimestamp bool /* Don't print a timestamp. */ Plain bool /* No newline, color, timestamp, or anything else. */ }
CLine is a line and a color to print. If Prompt is not empty, it is set as the prompt before printing the line.
type Color ¶
type Color int
Color represents a specific color.
type Shell ¶
type Shell struct {
// contains filtered or unexported fields
}
Shell is the shell used by an operator. It's a wrapper around golang.org/x/term.Terminal.
func New ¶
func New( ich chan<- string, och <-chan CLine, prompt string, noTimestamps bool, ) (*Shell, func(), error)
New puts the controlly TTY in raw mode and returns a new Shell wrapping stdio. Call Shell.Do to start processing lines and handle resizing and call the returned function to restore the TTY's state and clean up other resources. ich will be closed before Shell.Do returns. IF noTimestamps is true, no timestamps will be printed.
func (*Shell) Do ¶
Do proxies between the channels with which the shell was made and stdio as well as watches for SIGWINCH to handle shell resizing. Do closes the input channel passed to New. Do returns ErrOutputClosed if the output channel passed to New is closed.
func (*Shell) Logf ¶
Logf logs a line to the shell. It is similar to log.Printf but includes a color and only logs the time, not the date. Logf may be called from multiple goroutines simultaneously.