Documentation ¶
Overview ¶
Package termios implements basic termios operations including getting a tty struct, termio struct, a winsize struct, and setting raw mode. To get a TTY, call termios.New. To get a Termios, call tty.Get(); to set it, call tty.Set(*Termios) To set raw mode and then restore, one can do: tty := termios.NewTTY() restorer, err := tty.Raw() do things tty.Set(restorer)
Index ¶
- Constants
- func SetTermios(fd uintptr, ti *Termios) error
- func SetWinSize(fd uintptr, w *Winsize) error
- type TTY
- type TTYIO
- func (t *TTYIO) Ctty(c *exec.Cmd)
- func (t *TTYIO) Get() (*Termios, error)
- func (t *TTYIO) GetWinSize() (*Winsize, error)
- func (t *TTYIO) Raw() (*Termios, error)
- func (t *TTYIO) Read(b []byte) (int, error)
- func (t *TTYIO) Serial(baud int) (*Termios, error)
- func (t *TTYIO) Set(ti *Termios) error
- func (t *TTYIO) SetWinSize(w *Winsize) error
- func (t *TTYIO) Write(b []byte) (int, error)
- type Termios
- type Winsize
Constants ¶
const ( I = iota // Input control O // Output control C // Control L // Line control )
These consts describe the offsets into the termios struct of various elements.
Variables ¶
This section is empty.
Functions ¶
func SetTermios ¶
SetTermios sets tty parameters for an fd from a Termios.
func SetWinSize ¶
SetWinSize sets window size for an fd from a Winsize.
Types ¶
type TTY ¶
TTY is an os-independent version of the combined info in termios and window size structs. It is used to get/set info to the termios functions as well as marshal/unmarshal data in JSON format for dump and loading.
func GTTY ¶
GTTY returns the TTY struct for a given fd. It is like a New in many packages but the name GTTY is a tradition.
func (*TTY) STTY ¶
STTY uses a TTY * to set TTY settings on an fd. It returns a new TTY struct for the fd after the changes are made, and an error. It does not change the original TTY struct.
func (*TTY) SetOpts ¶
SetOpts sets opts in a TTY given an array of key-value pairs and booleans. The arguments are a variety of key-value pairs and booleans. booleans are cleared if the first char is a -, set otherwise.
func (*TTY) String ¶
String will stringify a TTY, including printing out the options all in the same order. The options are presented in the order: integer options as name:value boolean options which are set, printed as name, sorted by name boolean options which are clear, printed as ~name, sorted by name This ordering makes it a bit more readable: integer value, sorted set values, sorted clear values
type TTYIO ¶
type TTYIO struct {
// contains filtered or unexported fields
}
TTYIO contains state needed for controlling ttys. On many systems, but not all, this is just an os.File
func NewWithDev ¶
NewWithDev creates a new TTYIO with the specified device
func (*TTYIO) GetWinSize ¶
GetWinSize gets window size from a TTYIO.
func (*TTYIO) Serial ¶
Serial configure the serial TTY at given baudrate with ECHO and character conversion (CRNL, ERASE, KILL)
func (*TTYIO) SetWinSize ¶
SetWinSize sets window size for a TTYIO from a Winsize.
type Termios ¶
Termios is a struct for Termios operations.
func GetTermios ¶
GetTermios returns a filled-in Termios, from an fd.
func MakeRaw ¶
MakeRaw modifies Termio state so, if it used for an fd or tty, it will set it to raw mode.
func MakeSerialBaud ¶
MakeSerialBaud updates the Termios to set the baudrate
func MakeSerialDefault ¶
MakeSerialDefault updates the Termios to typical serial configuration:
- Ignore all flow control (modem, hardware, software...)
- Translate carriage return to newline on input
- Enable canonical mode: Input is available line by line, with line editing enabled (ERASE, KILL are supported)
- Local ECHO is added (and handled by line editing)
- Map newline to carriage return newline on output