Module posix.termio
Control Terminal I/O.
Functions and constants for controlling terminal behaviour.
Functions
| tcdrain (fd) | Wait for all written output to reach the terminal. |
| tcflow (fd, action) | Suspend transmission or receipt of data. |
| tcflush (fd, action) | Discard any data already written but not yet sent to the terminal. |
| tcgetattr (fd) | Get termios state. |
| tcgetwinsize (fd) | Get terminal window size. |
| tcsendbreak (fd, duration) | Send a stream of zero valued bits. |
| tcsetattr (fd, actions, a) | Set termios state. |
| tcsetwinsize (fd, winsize) | Set terminal window size. |
Tables
| PosixWinsize | Winsize record. |
| ccs | Control characters. |
| termios | Terminal attributes. |
Functions
- tcdrain (fd)
-
Wait for all written output to reach the terminal.
Parameters:
- fd int terminal descriptor to act on
Returns:
-
int
0, if successfulOr
- nil
- string error message
- int errnum
See also:
- tcflow (fd, action)
-
Suspend transmission or receipt of data.
Parameters:
- fd int terminal descriptor to act on
- action
int
one of
TCOOFF,TCOON,TCIOFForTCION
Returns:
-
int
0, if successfulOr
- nil
- string error message
- int errnum
See also:
- tcflush (fd, action)
-
Discard any data already written but not yet sent to the terminal.
Parameters:
- fd int terminal descriptor to act on
- action
int
one of
TCIFLUSH,TCOFLUSH,TCIOFLUSH
Returns:
-
int
0, if successfulOr
- nil
- string error message
- int errnum
See also:
- tcgetattr (fd)
-
Get termios state.
Parameters:
- fd int terminal descriptor
Returns:
-
error message if failed
Or
-
termios
terminal attributes, if successful
Or
- nil
- string error message
- int errnum
See also:
Usage:
local termios, errmsg = tcgetattr (fd)
- tcgetwinsize (fd)
-
Get terminal window size.
Parameters:
- fd int terminal descriptor to act on
Returns:
-
PosixWinsize
winsize current winsize for fd, if successful
Or
- nil
- string error message
- int errnum
See also:
Usage:
local termio = require "posix.termio" local ws, errmsg, errnum = termio.tcgetwinsize(fd) if ws then print("rows=", ws.row, "cols=", ws.col, "xpixel=", ws.xpixel, "ypixel=", ws.ypixel) else print("Error: ", errmsg, errnum) end
- tcsendbreak (fd, duration)
-
Send a stream of zero valued bits.
Parameters:
- fd int terminal descriptor
- duration int if non-zero, stream for some implementation defined time
Returns:
-
int
0, if successfulOr
- nil
- string error message
- int errnum
See also:
- tcsetattr (fd, actions, a)
-
Set termios state.
Parameters:
- fd int terminal descriptor to act on
- actions
int
bitwise OR of one or more of
TCSANOW,TCSADRAIN,TCSAFLUSHandTSASOFT - a
termios
table with fields from iflag, oflag, cflag, lflag and cc,
each formed by
boroperations with various posix constants
Returns:
-
int
0, if successfulOr
- nil
- string error message
- int errnum
See also:
Usage:
local termio = require "posix.termio" ok, errmsg = tcsetattr (fd, 0, { cc = { [termio.VTIME] = 0, [termio.VMIN] = 1 })
- tcsetwinsize (fd, winsize)
-
Set terminal window size.
Parameters:
- fd int terminal descriptor to act on
- winsize PosixWinsize to apply to fd
Returns:
-
int
0, if successfulOr
- nil
- string error message
- int errnum
See also:
Usage:
local termio = require "posix.termio" local ok, errmsg, errnum = termio.tcsetwinsize(fd, {row=24, col=80}) if not ok then print("Error: ", errmsg, errnum) end
Tables
- PosixWinsize
-
Winsize record.
Any fields not available in the underlying system will be
nilvalued.Fields:
- ws_row int rows, in characters
- ws_col int columns, in characters
- ws_xpixel int width, in pixels
- ws_ypixel int height, in pixels
- ccs
-
Control characters.
The field names below are not strings, but index constants each
referring to a terminal control character.
Fields:
- VINTR int interrupt control character
- VQUIT int quit control character
- WERASE int erase control character
- VKILL int kill control character
- VEOF int end-of-file control character
- VEOL int end-of-line control charactor
- VEOL2 int another end-of-line control charactor
- VMIN int 1
- VTIME int 0
- VSTART int xon/xoff start control character
- VSTOP int xon/xoff stop control character
- VSUSP int suspend control character
- termios
-
Terminal attributes.
The constants named below are all available in this submodule's namespace,
as long as they are supported by the underlying system.
Fields:
- cc ccs array of terminal control characters
- cflag
int
bitwise OR of zero or more of
CSIZE,CS5,CS6,CS7,CS8,CSTOPB,CREAD,PARENB,PARODD,HUPCL,CLOCALandCRTSCTS - iflag
int
input flags; bitwise OR of zero or more of
IGNBRK,BRKINT,IGNPAR,PARMRK,INPCK,ISTRIP,INLCR,IGNCR,ICRNL,IXON,IXOFF,IXANY, andIMAXBEL - lflag
int
local flags; bitwise OR of zero or more of
ISIG,ICANON,ECHO,ECHOE,ECHOK', 'ECHONL,NOFLSH,IEXTENandTOSTOP - oflag
int
output flags; bitwise OR of zero or more of
OPOST,ONLCR,OXTABS,ONOEOT,OCRNL,ONOCR,ONLRET,OFILL,NLDLY,TABDLY,CRDLY,FFDLY,BSDLY,VTDLYandOFDEL - ispeed
int
the input baud rate, one of
B0,B50,B75,B110,B134,B150,B200,B300,B600,B1200,B1800,B2400,B4800,B9600,B19200,B38400,B57600,B115200, - ospeed int the output baud rate (see ispeed for possible values)