termios

package
v0.0.0-...-0bb7f04 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2015 License: BSD-2-Clause, BSD-2-Clause Imports: 2 Imported by: 0

Documentation

Overview

Package termios is a simple Go wrapper to the POSIX Terminal Interface (POSIX Termios). See [1].

Similatities to the C API

The API exported by this package is very similar, though not identical, to the POSIX Termios C API. Some familiarity with the latter is required in order to use this package. See termios(3) or [2]. Any differences are covered by the package documentation.

The equivalent to the POSIX termios structure is defined as type Termios in this package, which is a structure with *no* exported fields. To access the standard POSIX termios flag fields (c_cflag, c_oflag, etc) use the methods:

Termios.CFlag() // Returns ptr to the c_cflag field equivalent.
Termios.OFlag() // Returns ptr to the c_oflag field equivalent.
... etc ...

The pointers returned by these methods are of type *TcFlag, wich provides convinience methods to set, clear, and test individual flags or groups of flags. E.g:

Termios.CFlag().Clr(termios.CSIZE).Set(termios.CS8)
Termios.CFlag().Clr(termios.CLOCAL|termios.HUPCL)

To access the contol-characters vector in termios (c_cc) use the following methods.

Termios.Cc(i) // Return control-char @ index i
Termios.CcSet(i, c) // Set control-char @ index i to c.

C API functions that take a termios-structure argument, like tc{get,set}attr, cf{set,get}{i,o}speed, etc. are mapped to Termios methods:

tcsetattr --> Termios.SetFd
tcgetattr --> Termios.GetFd
cfget{i,o}speed --> Termios.Get{I,O}Speed
cfset{i,o}speed --> Termios.Set{I,O}Speed
cfmakeraw --> Termios.MakeRaw

Unlike their C-API equivalent the speed-setting and speed-getting methods take and return numeric baudrate values (integers) expressed in bits-per-second (not Bxxx speed-codes).

C API functions that operate directly on fd's are mapped to similarly named functions:

tcflush --> Flush
tcdrain --> Drain
tcsendbreak --> SendBreak

C API constants (macros), such as mode-flags (e.g. CLOCAL, OPOST), retain their names.

Supported systems

Package termios should work on all systems that support the POSIX terminal interface, that is, on most Unix-like systems. Depending on the system, package termios can either be built to use the system's LIBC functions and macros through CGo, or as a pure-go package that issues system calls directly. In either case, the API presented by the package is identical.

References

[1] POSIX Terminal Interface
(https://en.wikipedia.org/wiki/POSIX_terminal_interface)

[2] POSIX.1-2008, Ch. 11: General Terminal Interface
(http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap11.html)

Index

Constants

View Source
const (
	// Input mode flags (access with Termios.IFlag())
	BRKINT = C.BRKINT
	ICRNL  = C.ICRNL
	IGNBRK = C.IGNBRK
	IGNCR  = C.IGNCR
	IGNPAR = C.IGNPAR
	INLCR  = C.INLCR
	INPCK  = C.INPCK
	ISTRIP = C.ISTRIP
	IXANY  = C.IXANY
	IXOFF  = C.IXOFF
	IXON   = C.IXON
	PARMRK = C.PARMRK
	// Non-standard (0 if unavailable)
	IMAXBEL = C.IMAXBEL
	IUCLC   = C.IUCLC
	IUTF8   = C.IUTF8

	// Output mode flags (access with Termios.OFlag())
	OPOST = C.OPOST

	// Control mode flags (access with Termios.CFlag())
	CSIZE  = C.CSIZE
	CS5    = C.CS5
	CS6    = C.CS6
	CS7    = C.CS7
	CS8    = C.CS8
	CSTOPB = C.CSTOPB
	CREAD  = C.CREAD
	PARENB = C.PARENB
	PARODD = C.PARODD
	HUPCL  = C.HUPCL
	CLOCAL = C.CLOCAL
	// Non-standard (0 if unavailable)
	CRTSCTS = C.CRTSCTS
	CMSPAR  = C.CMSPAR

	// Local mode flags (access with Termios.LFlag())
	ECHO   = C.ECHO
	ECHOE  = C.ECHOE
	ECHOK  = C.ECHOK
	ECHONL = C.ECHONL
	ICANON = C.ICANON
	IEXTEN = C.IEXTEN
	ISIG   = C.ISIG
	NOFLSH = C.NOFLSH
	TOSTOP = C.TOSTOP
	// Non-standard (0 if unavailable)
	PENDIN  = C.PENDIN
	ECHOCTL = C.ECHOCTL
	ECHOPRT = C.ECHOPRT
	ECHOKE  = C.ECHOKE
	FLUSHO  = C.FLUSHO
	EXTPROC = C.EXTPROC

	// Cc subscript names (access with Termios.{Cc,CcSet})
	VEOF   = C.VEOF
	VEOL   = C.VEOL
	VERASE = C.VERASE
	VINTR  = C.VINTR
	VKILL  = C.VKILL
	VMIN   = C.VMIN
	VQUIT  = C.VQUIT
	VSTART = C.VSTART
	VSTOP  = C.VSTOP
	VSUSP  = C.VSUSP
	VTIME  = C.VTIME
	// Non-standard (-1 if unavailable)
	VREPRINT = C.VREPRINT
	VDISCARD = C.VDISCARD
	VWERASE  = C.VWERASE
	VLNEXT   = C.VLNEXT
	VEOL2    = C.VEOL2

	// Values for the act argument of Termios.SetFd
	TCSANOW   = C.TCSANOW
	TCSADRAIN = C.TCSADRAIN
	TCSAFLUSH = C.TCSAFLUSH

	// Queue selectors for function Flush
	TCIFLUSH  = C.TCIFLUSH
	TCOFLUSH  = C.TCOFLUSH
	TCIOFLUSH = C.TCIOFLUSH

	// Values for the act argument of Flow
	TCOOFF = C.TCOOFF
	TCOON  = C.TCOON
	TCIOFF = C.TCIOFF
	TCION  = C.TCION
)

Variables

This section is empty.

Functions

func Drain

func Drain(fd int) error

Drain blocks until all data written to the terminal fd are transmitted. See also tcdrain(3). If the system call is interrupted by a signal, Drain retries it automatically.

func Flow

func Flow(fd int, act int) error

Flow suspends or resumes the transmission or reception of data on the terminal associated with fd, depending on the value of the act argument. The act argument value must be one of: TCOOFF (suspend transmission), TCOON (resume transmission), TCIOFF (suspend reception by sending a STOP char), TCION (resume reception by sending a START char). See also tcflow(3).

func Flush

func Flush(fd int, qsel int) error

Flush discards data received but not yet read (input queue), and/or data written but not yet transmitted (output queue), depending on the value of the qsel argument. Argument qsel must be one of the constants TCIFLUSH (flush input queue), TCOFLUSH (flush output queue), TCIOFLUSH (flush both queues). See also tcflush(3).

func GetPgrp

func GetPgrp(fd int) (pgid int, err error)

GetPgrp returns the process group ID of the foreground process group associated with the terminal. See tcgetpgrp(3).

func SendBreak

func SendBreak(fd int) error

SendBreak sends a continuous stream of zero bits to the terminal corresponding to file-descriptor fd, lasting between 0.25 and 0.5 seconds.

func SetPgrp

func SetPgrp(fd int, pgid int) error

SetPgrp sets the foreground process group ID associated with the terminal to pgid. See tcsetpgrp(3).

Types

type Cc

type Cc C.cc_t

Cc is a Termios control character

type TcFlag

type TcFlag C.tcflag_t

TcFlag is a word containing Termios mode-flags

func (*TcFlag) All

func (w *TcFlag) All(f TcFlag) bool

All returns true if all of the flags set in f are also set in w.

func (*TcFlag) Any

func (w *TcFlag) Any(f TcFlag) bool

Any returns true if any of flags set in f are also set in w.

func (*TcFlag) Clr

func (w *TcFlag) Clr(f TcFlag) *TcFlag

Clr clears (lowers) in w the flags that are set in f. It does not affect the other flags in w. Returns (a pointer to) w.

func (*TcFlag) Msk

func (w *TcFlag) Msk(f TcFlag) TcFlag

Msk returns the flags in w masked by f (that is, the values of the flags in w for which the equivalent flags in f are set). It does not modify w.

func (*TcFlag) Set

func (w *TcFlag) Set(f TcFlag) *TcFlag

Set sets (raises) in w the flags that are set in f. It does not affect the other flags in w. Returns (a pointer to) w.

func (*TcFlag) Val

func (w *TcFlag) Val() TcFlag

Val returns the flags in w (i.e the value pointed-to by w)

type Termios

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

Termios is the terminal-attributes structure

func (*Termios) CFlag

func (t *Termios) CFlag() *TcFlag

CFlag returns a pointer to the Termios field keeping the control-mode flags

func (*Termios) Cc

func (t *Termios) Cc(idx int) Cc

Cc returns the Termios control character in index idx

func (*Termios) CcSet

func (t *Termios) CcSet(idx int, c Cc)

CcSet sets the Termios control character in index idx to c.

func (*Termios) GetFd

func (t *Termios) GetFd(fd int) error

GetFd reads the attributes of the terminal corresponding to the file-descriptor fd and stores them in the Termios structure t. See tcgetattr(3) for more.

func (*Termios) GetISpeed

func (t *Termios) GetISpeed() (speed int, err error)

GetISpeed returns the input (receiver) baudrate in Termios structure t as a numerical (integer) value in bits-per-second. Returns err == syscal.EINVAL if the baudrate in t cannot be decoded. See also getispeed(3).

func (*Termios) GetOSpeed

func (t *Termios) GetOSpeed() (speed int, err error)

GetOSpeed returns the output (transmitter) baudrate in Termios structure t as a numerical (integer) value in bits-per-second. Returns err == syscal.EINVAL if the baudrate in t cannot be decoded. See also getospeed(3).

func (*Termios) IFlag

func (t *Termios) IFlag() *TcFlag

IFlag returns a pointer to the Termios field keeping the input-mode flags

func (*Termios) LFlag

func (t *Termios) LFlag() *TcFlag

LFlag returns a pointer to the Termios field keeping the local-mode flags

func (*Termios) MakeRaw

func (t *Termios) MakeRaw()

MakeRaw sets the terminal attributes in t to values appropriate for configuring the terminal to "raw" mode: Input available character by character, echoing disabled, and all special processing of terminal input and output characters disabled. Notice that MakeRaw does not actually configure the terminal, it only sets the attributes in t. In order to configure the terminal, you must subsequently call the t.SetFd method.

func (*Termios) OFlag

func (t *Termios) OFlag() *TcFlag

OFlag returns a pointer to the Termios field keeping the output-mode flags

func (*Termios) SetFd

func (t *Termios) SetFd(fd int, act int) error

SetFd configures the terminal corresponding to the file-descriptor fd using the attributes in the Termios structure t. Argument act must be one of the constants TCSANOW, TCSADRAIN, TCSAFLUSH. See tcsetattr(3) for more. If the system call is interrupted by a signal, SetFd retries it automatically.

func (*Termios) SetISpeed

func (t *Termios) SetISpeed(speed int) error

SetISpeed sets the input (receiver) baudrate in Termios structure t to speed. Argument speed must be a numerical (integer) baudrate value in bits-per-second. Returns syscall.EINVAL if the requested baudrate is not supported. See also cfsetispeed(3).

func (*Termios) SetOSpeed

func (t *Termios) SetOSpeed(speed int) error

SetOSpeed sets the output (transmitter) baudrate in termios structure t to speed. Argument speed must be a numerical (integer) baudrate value in bits-per-second. Returns syscall.EINVAL if the requested baudrate is not supported. See also cfsetospeed(3).

Jump to

Keyboard shortcuts

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