termios

package module
v0.0.0-...-06b8aa5 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2016 License: MIT Imports: 5 Imported by: 0

README

termios

This is a pure-go implementation of (most of) the functions described in termios(3) on Linux (although you should probably read tcgetattr(3) and tcsendbreak(3) from FreeBSD; at least to me they were much clearer).

Only tested on Linux, and will need splitting into arch-specific bits to work on *BSD, but no strong reason for it not to work there. Patches welcome!

Documentation

Index

Constants

View Source
const (
	// linux-specific c_cflag bits:
	CBAUD   = uint32(unix.CBAUD)
	CBAUDEX = uint32(unix.CBAUDEX)
)

Linux-specific bit meanings, from bits/termios.h

View Source
const (
	// taken from bits/termios.h
	TCOOFF = 0
	TCOON  = 1
	TCIOFF = 2
	TCION  = 3
)

Apparently missing from sys/unix

Variables

View Source
var (
	ErrNotImplemented = errors.New("not implemented")
	ErrInvalidAction  = errors.New("invalid action")
)

Functions

func Drain

func Drain(fd uintptr) error

Drain waits until all output written to the terminal referenced by fd has been transmitted to the terminal.

func Flow

func Flow(fd uintptr, action int) error

Flow manages the suspending of data transmission or reception on the terminal referenced by fd. The value of action must be one of the following:

TCOOFF  Suspend output.
TCOON   Restart suspended output.
TCIOFF  Transmit a STOP character (the XOFF in XON/XOFF)
TCION   Transmit a START character (the XON).

func Flush

func Flush(fd uintptr, queue Queue) error

Flush discards data written to the terminal but not transmitted, or received from the terminal but not read, depending on the queue.

InputQueue received but not read. OutputQueue written but not transmitted. AnyQueue both

func GetWinSize

func GetWinSize(fd uintptr) (width int, height int, err error)

GetWinSize gets the current size of the terminal referred to by fd.

func SendBreak

func SendBreak(fd uintptr, duration int) error

SendBreak transmits a continuous stream of zeros for between 0.25 and 0.5 seconds if duration is 0, or for the given number of deciseconds if not, if the terminal supports breaks.

Note this is TCSBRKP in tty_ioctl(4); this one seems saner than TCSBRK/tcsendbreak(3).

func SetWinSize

func SetWinSize(fd uintptr, width, height int) error

SetWinSize sets the size of the terminal referred to by fd.

Types

type Queue

type Queue uint8
const (
	AnyQueue Queue = iota
	InputQueue
	OutputQueue
)

type Termios

type Termios unix.Termios

func GetAttr

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

GetAttr gets the attributes of the given terminal.

func GetLock

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

GetLock gets the locking status of the termios structure of the given terminal. See tty_ioctl(4).

func (*Termios) DrainAndSetAttr

func (tio *Termios) DrainAndSetAttr(fd uintptr) error

DrainAndSetAttr sets the attributes of the given terminal from this termios structure, after all output written to fd has been transmitted. This option should be used when changing parameters that affect output. See tcsetattr(3).

func (*Termios) FlushAndSetAttr

func (tio *Termios) FlushAndSetAttr(fd uintptr) error

FlushAndSetAttr sets the attributes of the given terminal from this termios structure, “after all output written to fd has been transmitted, and all input that has been received but not read will be discarded before the change is made”. See tcsetattr(3).

func (*Termios) GetSpeed

func (tio *Termios) GetSpeed() (in int, out int)

GetSpeed gets the stored baud rate.

NOTE linux doesn't support different speeds for in and out; everything is outSpeed

func (*Termios) MakeRaw

func (tio *Termios) MakeRaw() *Termios

MakeRaw returns a copy of the termios structure with the flags set to a state disabling all input and output processing, giving a “raw I/O path”. See cfmakeraw(3). Note the exact flags are platform-dependent.

Note also this does *not* apply it to a terminal; for that call one of the SetAttr methods on the returned struct.

func (*Termios) SetAttr

func (tio *Termios) SetAttr(fd uintptr) error

SetAttr sets the attributes of the given terminal from this termios structure, immediately. See tcsetattr(3).

func (*Termios) SetLock

func (tio *Termios) SetLock(fd uintptr) error

SetLock sets the locking status of the termios structure of the given terminal. Needs CAP_SYS_ADMIN. See tty_ioctl(4).

func (*Termios) SetSpeed

func (tio *Termios) SetSpeed(_ int, speed int) error

SetSpeed sets the baud rate.

NOTE linux doesn't support different speeds for in and out; everything is outSpeed.

Jump to

Keyboard shortcuts

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