termutil

package
v0.0.0-...-f4dd720 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2024 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package termutil provides structures and helper functions to work with terminal (state, sizes). Taken from docker-ce source code.

Index

Constants

This section is empty.

Variables

View Source
var ASCII = []string{
	"ctrl-@",
	"ctrl-a",
	"ctrl-b",
	"ctrl-c",
	"ctrl-d",
	"ctrl-e",
	"ctrl-f",
	"ctrl-g",
	"ctrl-h",
	"ctrl-i",
	"ctrl-j",
	"ctrl-k",
	"ctrl-l",
	"ctrl-m",
	"ctrl-n",
	"ctrl-o",
	"ctrl-p",
	"ctrl-q",
	"ctrl-r",
	"ctrl-s",
	"ctrl-t",
	"ctrl-u",
	"ctrl-v",
	"ctrl-w",
	"ctrl-x",
	"ctrl-y",
	"ctrl-z",
	"ctrl-[",
	"ctrl-\\",
	"ctrl-]",
	"ctrl-^",
	"ctrl-_",
}

ASCII lists the possible supported ASCII key sequence nolint: gochecknoglobals

View Source
var (
	// ErrInvalidState is returned if the state of the terminal is invalid.
	ErrInvalidState = errors.New("invalid terminal state")
)
View Source
var ErrNoTTY = fmt.Errorf("not a TTY")

ErrNoTTY defines the errormessage to return when a terminal is not a tty

Functions

func Err

func Err() *os.File

Err returns a file pointer to stderr of a new terminal

func In

func In() *os.File

In returns a file pointer to stdin of a new terminal

func IsTTY

func IsTTY() bool

IsTTY returns true if the new terminal is a tty

func MakeRaw

func MakeRaw() error

MakeRaw creates a new terminal with raw output

func NewEscapeProxy

func NewEscapeProxy(r io.Reader, escapeKeys []byte) io.Reader

NewEscapeProxy returns a new TTY proxy reader which wraps the given reader and detects when the specified escape keys are read, in which case the Read method will return an error of type EscapeError.

func Out

func Out() *os.File

Out returns a file pointer to stdout of a new terminal

func Restore

func Restore() error

Restore returns a new terminal with no in or out state

func SetWinsize

func SetWinsize(ws *Winsize) error

SetWinsize sets the window size of a new terminal

func ToBytes

func ToBytes(keys string) ([]byte, error)

ToBytes converts a string representing a suite of key-sequence to the corresponding ASCII code.

Types

type EscapeError

type EscapeError struct{}

EscapeError is special error which returned by a TTY proxy reader's Read() method in case its detach escape sequence is read.

func (EscapeError) Error

func (EscapeError) Error() string

type State

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

State represents the state of the terminal.

type Terminal

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

Terminal describes a terminal it stores file pointers to the in, out and error file handers and the state of the in and output

func NewTerminal

func NewTerminal(in, out, err *os.File) *Terminal

NewTerminal returns a pointer to a new Terminal struct using the given in, out and err files as files for input, output and error handling.

func StdTerminal

func StdTerminal() *Terminal

StdTerminal returns a pointer to a new terminal

func (*Terminal) Close

func (t *Terminal) Close() error

Close closes the terminal it is called on

func (*Terminal) Err

func (t *Terminal) Err() *os.File

Err returns the pointer to the error of the terminal the method is called on

func (*Terminal) GetState

func (t *Terminal) GetState() (*Termios, error)

GetState returns the current state of the terminal the method is called on

func (*Terminal) GetWinsize

func (t *Terminal) GetWinsize() (*Winsize, error)

GetWinsize returns the current window size of the terminal the method is called on

func (*Terminal) In

func (t *Terminal) In() *os.File

In returns the pointer to the input of the terminal the method is called on

func (*Terminal) IsTTY

func (t *Terminal) IsTTY() bool

IsTTY returns true if the terminal the method is called on is a tty

func (*Terminal) MakeRaw

func (t *Terminal) MakeRaw() error

MakeRaw sets the terminal output to raw

func (*Terminal) Out

func (t *Terminal) Out() *os.File

Out returns the pointer to the output of the terminal the method is called on

func (*Terminal) Restore

func (t *Terminal) Restore() error

Restore restores the terminal by setting the input and output state to nil

func (*Terminal) SetWinsize

func (t *Terminal) SetWinsize(ws *Winsize) error

SetWinsize sets the window size of terminal the method is called on

type Termios

type Termios unix.Termios

Termios is the Unix API for terminal I/O.

func GetState

func GetState() (*Termios, error)

GetState returns the state of a new terminal

type Winsize

type Winsize struct {
	Height uint16
	Width  uint16
	// contains filtered or unexported fields
}

Winsize represents the size of the terminal window.

func GetWinsize

func GetWinsize() (*Winsize, error)

GetWinsize returns a new terminals window size

Jump to

Keyboard shortcuts

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