Documentation ¶
Index ¶
- func GetSize(fd uintptr) *remotecommand.TerminalSize
- func IsTerminal(i interface{}) bool
- func NewMaxWidthWriter(w io.Writer, maxWidth uint) io.Writer
- func NewPunchCardWriter(w io.Writer) io.Writer
- func NewResponsiveWriter(w io.Writer) io.Writer
- func NewWordWrapWriter(w io.Writer, limit uint) io.Writer
- func SetSize(fd uintptr, size remotecommand.TerminalSize) error
- type SafeFunc
- type TTY
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
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
func NewMaxWidthWriter ¶ added in v1.5.0
NewMaxWidthWriter is a Writer that supports a limit of characters on every line, but doesn't do any word wrapping automatically.
func NewPunchCardWriter ¶ added in v1.5.0
NewPunchCardWriter is a NewWordWrapWriter that limits the line width to 80 columns.
func NewResponsiveWriter ¶ added in v1.5.0
NewResponsiveWriter creates a Writer that detects the column width of the terminal we are in, and adjusts every line width to fit and use recommended terminal sizes for better readability. Does proper word wrapping automatically.
if terminal width >= 120 columns use 120 columns if terminal width >= 100 columns use 100 columns if terminal width >= 80 columns use 80 columns
In case we're not in a terminal or if it's smaller than 80 columns width, doesn't do any wrapping.
func NewWordWrapWriter ¶ added in v1.5.0
NewWordWrapWriter is a Writer that supports a limit of characters on every line and does auto word wrapping that respects that limit.
func SetSize ¶
func SetSize(fd uintptr, size remotecommand.TerminalSize) error
SetSize sets the terminal size associated with fd.
Types ¶
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 ¶
IsTerminalIn returns true if t.In is a terminal. Does not check /dev/tty even if TryDev is set.
func (TTY) IsTerminalOut ¶
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 ¶
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).