< Alcor6L < eLua

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

Functions

term.clrscr

Clear the screen

term.clrscr()

term.clreol

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

term.clreol()

term.moveto

Move the cursor to the specified coordinates

term.moveto( x, y )
  • x - the column (starting with 1)
  • y - the line (starting with 1)

term.moveup

Move the cursor up

term.moveup( delta )
  • delta - number of lines to move the cursor up.

term.movedown

Move the cursor down

term.movedown( delta )
  • delta - number of lines to move the cursor down

term.moveleft

Move the cursor left

term.moveleft( delta )
  • delta - number of columns to move the cursor left

term.moveright

Move the cursor right

term.moveright( delta )
  • delta - number of columns to move the cursor right

term.getlines

Get the number of lines in the terminal

numlines = term.getlines()

Returns:

  • numlines - The number of lines in the terminal

term.getcols

Get the number of columns in the terminal

numcols = term.getcols()

Returns:

  • numcols - The number of columns in the terminal

term.print

Write one or more strings in the terminal

term.print( [ x, y ], str1, [ str2, ..., strn ] )
  • 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

getcx

Get the current column of the cursor

cx = term.getcx()

Returns:

  • cx - The column of the cursor

term.getcy

Get the current line of the cursor

cy = term.getcy()

Returns:

  • cy - The line of the cursor

term.getchar

Read a char (a key press) from the terminal

ch = term.getchar( [ mode ] )
  • 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:

  • ch - 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 codeMeaning
KC_UPthe UP key on the terminal
KC_DOWNthe DOWN key on the terminal
KC_LEFTthe LEFT key on the terminal
KC_RIGHTthe RIGHT key on the terminal
KC_HOMEthe HOME key on the terminal
KC_ENDthe END key on the terminal
KC_PAGEUPthe PAGE UP key on the terminal
KC_PAGEDOWNthe PAGE DOWN key on the terminal
KC_ENTERthe ENTER (CR) key on the terminal
KC_TABthe TAB key on the terminal
KC_BACKSPACEthe BACKSPACE key on the terminal
KC_ESCthe ESC (escape) key on the terminal
This article is issued from Wikibooks. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.