term

package
v0.2.8 Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2018 License: Apache-2.0 Imports: 7 Imported by: 0

README

Term package

Content of this package were copied from github.com/kubernetes/kubernetes/pkg/kubectl/util/term

but modified to remove dependency to following packages:

  • k8s.io/apimachinery/pkg/util/runtime
  • k8s.io/client-go/tools/remotecommand

because those caused a lot of more dependencies but were not required for the functionality.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsTerminal

func IsTerminal(i interface{}) bool

IsTerminal returns whether the passed object is a terminal or not

Types

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
	// 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() *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 ...*TerminalSize) 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).

type TerminalSize

type TerminalSize struct {
	Width  uint16
	Height uint16
}

TerminalSize represents the width and height of a terminal.

func GetSize

func GetSize(fd uintptr) *TerminalSize

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

type TerminalSizeQueue

type TerminalSizeQueue interface {
	// Next returns the new terminal size after the terminal has been resized. It returns nil when
	// monitoring has been stopped.
	Next() *TerminalSize
}

TerminalSizeQueue is capable of returning terminal resize events as they occur.

Jump to

Keyboard shortcuts

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