term

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2021 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

copied from docker/docker/pkg/jsonmessage/jsonmesage.go, fix the row align

copied from github.com/kubernetes/kubernetes/pkg/kubectl/cmd/util/resize.go

copied from github.com/kubernetes/kubernetes/pkg/kubectl/cmd/util/term.go

Index

Constants

View Source
const RFC3339NanoFixed = "2006-01-02T15:04:05.000000000Z07:00"

RFC3339NanoFixed is time.RFC3339Nano with nanoseconds padded using zeros to ensure the formatted time isalways the same number of characters.

Variables

This section is empty.

Functions

func DisplayJSONMessagesStream

func DisplayJSONMessagesStream(in io.Reader, out io.Writer, terminalFd uintptr, isTerminal bool, auxCallback func(*json.RawMessage)) error

DisplayJSONMessagesStream displays a json message stream from `in` to `out`, `isTerminal` describes if `out` is a terminal. If this is the case, it will print `\n` at the end of each line and move the cursor while displaying.

func DisplayJSONMessagesToStream

func DisplayJSONMessagesToStream(in io.Reader, stream stream, auxCallback func(*json.RawMessage)) error

DisplayJSONMessagesToStream prints json messages to the output stream

func GetSize

func GetSize(fd uintptr) *remotecommand.TerminalSize

GetSize returns the current size of the terminal associated with fd.

func IsTerminal

func IsTerminal(i interface{}) bool

IsTerminal returns whether the passed object is a terminal or not

Types

type JSONError

type JSONError struct {
	Code    int    `json:"code,omitempty"`
	Message string `json:"message,omitempty"`
}

JSONError wraps a concrete Code and Message, `Code` is is an integer error code, `Message` is the error message.

func (*JSONError) Error

func (e *JSONError) Error() string

type JSONMessage

type JSONMessage struct {
	Stream          string        `json:"stream,omitempty"`
	Status          string        `json:"status,omitempty"`
	Progress        *JSONProgress `json:"progressDetail,omitempty"`
	ProgressMessage string        `json:"progress,omitempty"` //deprecated
	ID              string        `json:"id,omitempty"`
	From            string        `json:"from,omitempty"`
	Time            int64         `json:"time,omitempty"`
	TimeNano        int64         `json:"timeNano,omitempty"`
	Error           *JSONError    `json:"errorDetail,omitempty"`
	ErrorMessage    string        `json:"error,omitempty"` //deprecated
	// Aux contains out-of-band data, such as digests for push signing and image id after building.
	Aux *json.RawMessage `json:"aux,omitempty"`
}

JSONMessage defines a message struct. It describes the created time, where it from, status, ID of the message. It's used for docker events.

func (*JSONMessage) Display

func (jm *JSONMessage) Display(out io.Writer, termInfo termInfo) error

Display displays the JSONMessage to `out`. `termInfo` is non-nil if `out` is a terminal. If this is the case, it will erase the entire current line when displaying the progressbar.

type JSONProgress

type JSONProgress struct {
	Current int64 `json:"current,omitempty"`
	Total   int64 `json:"total,omitempty"`
	Start   int64 `json:"start,omitempty"`
	// If true, don't show xB/yB
	HideCounts bool   `json:"hidecounts,omitempty"`
	Units      string `json:"units,omitempty"`
	// contains filtered or unexported fields
}

JSONProgress describes a Progress. terminalFd is the fd of the current terminal, Start is the initial value for the operation. Current is the current status and value of the progress made towards Total. Total is the end value describing when we made 100% progress for an operation.

func (*JSONProgress) String

func (p *JSONProgress) String() string

type SafeFunc

type SafeFunc func() error

SafeFunc is a function to be invoked by TTY.

type TTY

type TTY struct {
	// In is a reader representing stdin. It is a required field.
	In io.Reader
	// Out is a writer representing stdout. It must be set to support terminal resizing. It is an
	// optional field.
	Out io.Writer
	// Raw is true if the terminal should be set raw.
	Raw bool
	// TryDev indicates the TTY should try to open /dev/tty if the provided input
	// is not a file descriptor.
	TryDev bool
	// Parent is an optional interrupt handler provided to this function - if provided
	// it will be invoked after the terminal state is restored. If it is not provided,
	// a signal received during the TTY will result in os.Exit(0) being invoked.
	Parent *interrupt.Handler
	// contains filtered or unexported fields
}

TTY helps invoke a function and preserve the state of the terminal, even if the process is terminated during execution. It also provides support for terminal resizing for remote command execution/attachment.

func (TTY) GetSize

func (t TTY) GetSize() *remotecommand.TerminalSize

GetSize returns the current size of the user's terminal. If it isn't a terminal, nil is returned.

func (TTY) IsTerminalIn

func (t TTY) IsTerminalIn() bool

IsTerminalIn returns true if t.In is a terminal. Does not check /dev/tty even if TryDev is set.

func (TTY) IsTerminalOut

func (t TTY) IsTerminalOut() bool

IsTerminalOut returns true if t.Out is a terminal. Does not check /dev/tty even if TryDev is set.

func (*TTY) MonitorSize

func (t *TTY) MonitorSize(initialSizes ...*remotecommand.TerminalSize) remotecommand.TerminalSizeQueue

MonitorSize monitors the terminal's size. It returns a TerminalSizeQueue primed with initialSizes, or nil if there's no TTY present.

func (TTY) Safe

func (t TTY) Safe(fn SafeFunc) error

Safe invokes the provided function and will attempt to ensure that when the function returns (or a termination signal is sent) that the terminal state is reset to the condition it was in prior to the function being invoked. If t.Raw is true the terminal will be put into raw mode prior to calling the function. If the input file descriptor is not a TTY and TryDev is true, the /dev/tty file will be opened (if available).

Jump to

Keyboard shortcuts

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