# 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 successful

  ### Or

  1. nil
  2. string error message
  3. int errnum

  ### See also:

  tcdrain(3)
tcflow (fd, action)
  Suspend transmission or receipt of data.

  ### Parameters:

  - fd int terminal descriptor to act on
  - action int one of `TCOOFF`, `TCOON`, `TCIOFF` or `TCION`

  ### Returns:

  int `0`, if successful

  ### Or

  1. nil
  2. string error message
  3. int errnum

  ### See also:

  tcflow(3)
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 successful

  ### Or

  1. nil
  2. string error message
  3. int errnum

  ### See also:

  tcflush(3)
tcgetattr (fd)
  Get termios state.

  ### Parameters:

  - fd int terminal descriptor

  ### Returns:

  error message if failed

  ### Or

  termios terminal attributes, if successful

  ### Or

  1. nil
  2. string error message
  3. int errnum

  ### See also:

  tcgetattr(3)

  ### 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

  1. nil
  2. string error message
  3. int errnum

  ### See also:

  tcgetwinsize(3)

  ### 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 successful

  ### Or

  1. nil
  2. string error message
  3. int errnum

  ### See also:

  tcsendbreak(3)
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`, `TCSAFLUSH` and `TSASOFT`
  - a termios table with fields from iflag, oflag, cflag, lflag and cc, each formed by `bor` operations with various posix constants

  ### Returns:

  int `0`, if successful

  ### Or

  1. nil
  2. string error message
  3. int errnum

  ### See also:

  tcsetattr(3)

  ### 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 successful

  ### Or

  1. nil
  2. string error message
  3. int errnum

  ### See also:

  tcsetwinsize(3)

  ### 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 `nil` valued.

  ### 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`, `CLOCAL` and `CRTSCTS`
  - iflag int input flags; bitwise OR of zero or more of `IGNBRK`, `BRKINT`, `IGNPAR`, `PARMRK`, `INPCK`, `ISTRIP`, `INLCR`, `IGNCR`, `ICRNL`, `IXON`, `IXOFF`, `IXANY`, and `IMAXBEL`
  - lflag int local flags; bitwise OR of zero or more of `ISIG`, `ICANON`, `ECHO`, `ECHOE`, `ECHOK', 'ECHONL`, `NOFLSH`, `IEXTEN` and `TOSTOP`
  - oflag int output flags; bitwise OR of zero or more of `OPOST`, `ONLCR`, `OXTABS`, `ONOEOT`, `OCRNL`, `ONOCR`, `ONLRET`, `OFILL`, `NLDLY`, `TABDLY`, `CRDLY`, `FFDLY`, `BSDLY`, `VTDLY` and `OFDEL`
  - 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)

generated by LDoc 1.5.0 Last updated 2025-02-16 13:16:41