Overview

This module contains functions for accessing ANSI-compatible terminals (and terminal emulators) from Lua.

Functions

term.clrscr()

Clear the screen

Arguments: none.

Returns: nothing.

term.clreol()

Clear from the current cursor position to the end of the line

Arguments: none.

Returns: nothing.

term.moveto( x, y )

Move the cursor to the specified coordinates

Arguments:

  • x - the column (starting with 1)
  • y - the line (starting with 1)

Returns: nothing.

term.moveup( delta )

Move the cursor up

Arguments: delta - number of lines to move the cursor up

Returns: nothing.

term.movedown( delta )

Move the cursor down

Arguments: delta - number of lines to move the cursor down

Returns: nothing.

term.moveleft( delta )

Move the cursor left

Arguments: delta - number of columns to move the cursor left

Returns: nothing.

term.moveright( delta )

Move the cursor right

Arguments: delta - number of columns to move the cursor right

Returns: nothing.

numlines = term.getlines()

Get the number of lines in the terminal

Arguments: none.

Returns: The number of lines in the terminal

numcols = term.getcols()

Get the number of columns in the terminal

Arguments: none.

Returns: The number of columns in the terminal

term.print( [ x, y ], str1, [ str2, ..., strn ] )

Write one or more strings in the terminal

Arguments:

  • x (optional) - write the string at this column. If x is specified, y must also be specified
  • y (optional) - write the string at this line. If y is specified, x must also be specified
  • str1 - the first string to write
  • str2 (optional) - the second string to write
  • strn (optional) - the nth string to write

Returns: nothing.

cx = term.getcx()

Get the current column of the cursor

Arguments: none.

Returns: The column of the cursor

cy = term.getcy()

Get the current line of the cursor

Arguments: none.

Returns: The line of the cursor

ch = term.getchar( [ mode ] )

Read a char (a key press) from the terminal

Arguments: mode (optional) - terminal input mode. It can be either:

  • term.WAIT - wait for a key to be pressed, then return it. This is the default behaviour if mode is not specified.
  • term.NOWAIT - if a key was pressed on the terminal return it, otherwise return -1.

Returns: The char read from a terminal or -1 if no char is available. The 'char' can be an actual ASCII char, or a 'pseudo-char' which encodes special keys on the keyboard. The list of the special chars and their meaning is given in the table below:

Key code Meaning
KC_UP the UP key on the terminal
KC_DOWN the DOWN key on the terminal
KC_LEFT the LEFT key on the terminal
KC_RIGHT the RIGHT key on the terminal
KC_HOME the HOME key on the terminal
KC_END the END key on the terminal
KC_PAGEUP the PAGE UP key on the terminal
KC_PAGEDOWN the PAGE DOWN key on the terminal
KC_ENTER the ENTER (CR) key on the terminal
KC_TAB the TAB key on the terminal
KC_BACKSPACE the BACKSPACE key on the terminal
KC_ESC the ESC (escape) key on the terminal