termios

package
v0.14.0 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2024 License: BSD-3-Clause Imports: 9 Imported by: 213

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

View Source
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

func SetTermios(fd uintptr, ti *Termios) error

SetTermios sets tty parameters for an fd from a Termios.

func SetWinSize

func SetWinSize(fd uintptr, w *Winsize) error

SetWinSize sets window size for an fd from a Winsize.

Types

type TTY

type TTY struct {
	Ispeed int
	Ospeed int
	Row    int
	Col    int

	CC map[string]uint8

	Opts map[string]bool
}

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

func GTTY(fd int) (*TTY, error)

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 Raw

func Raw(fd int) (*TTY, error)

Raw sets a TTY into raw mode, returning a TTY struct

func (*TTY) STTY

func (t *TTY) STTY(fd int) (*TTY, error)

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

func (t *TTY) SetOpts(opts []string) error

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

func (t *TTY) String() 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 New

func New() (*TTYIO, error)

New creates a new TTYIO using /dev/tty

func NewTTYS

func NewTTYS(port string) (*TTYIO, error)

NewTTYS returns a new TTYIO.

func NewWithDev

func NewWithDev(device string) (*TTYIO, error)

NewWithDev creates a new TTYIO with the specified device

func (*TTYIO) Ctty

func (t *TTYIO) Ctty(c *exec.Cmd)

Ctty sets the control tty into a Cmd, from a TTYIO.

func (*TTYIO) Get

func (t *TTYIO) Get() (*Termios, error)

Get terms a Termios from a TTYIO.

func (*TTYIO) GetWinSize

func (t *TTYIO) GetWinSize() (*Winsize, error)

GetWinSize gets window size from a TTYIO.

func (*TTYIO) Raw

func (t *TTYIO) Raw() (*Termios, error)

Raw sets the tty into raw mode.

func (*TTYIO) Read

func (t *TTYIO) Read(b []byte) (int, error)

func (*TTYIO) Serial

func (t *TTYIO) Serial(baud int) (*Termios, error)

Serial configure the serial TTY at given baudrate with ECHO and character conversion (CRNL, ERASE, KILL)

func (*TTYIO) Set

func (t *TTYIO) Set(ti *Termios) error

Set sets tty parameters for a TTYIO from a Termios.

func (*TTYIO) SetWinSize

func (t *TTYIO) SetWinSize(w *Winsize) error

SetWinSize sets window size for a TTYIO from a Winsize.

func (*TTYIO) Write

func (t *TTYIO) Write(b []byte) (int, error)

type Termios

type Termios struct {
	unix.Termios
}

Termios is a struct for Termios operations.

func GetTermios

func GetTermios(fd uintptr) (*Termios, error)

GetTermios returns a filled-in Termios, from an fd.

func MakeRaw

func MakeRaw(term *Termios) *Termios

MakeRaw modifies Termio state so, if it used for an fd or tty, it will set it to raw mode.

func MakeSerialBaud

func MakeSerialBaud(term *Termios, baud int) (*Termios, error)

MakeSerialBaud updates the Termios to set the baudrate

func MakeSerialDefault

func MakeSerialDefault(term *Termios) *Termios

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

type Winsize

type Winsize struct {
	unix.Winsize
}

Winsize embeds unix.Winsize.

func GetWinSize

func GetWinSize(fd uintptr) (*Winsize, error)

GetWinSize gets window size from an fd.

Jump to

Keyboard shortcuts

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