-
Notifications
You must be signed in to change notification settings - Fork 433
API Term
Vexatos edited this page Jul 13, 2014
·
6 revisions
For those that don't like images: the wiki has moved to a new place, http://ocdoc.cil.li/.
This wiki will no longer be updated.
Provides a simplified way of writing text to screens and reading user input, so you don't have to manually interact with the GPU API for these cases.
-
term.isAvailable(): boolean
Returns whether the term API is available for use, i.e. whether a primary GPU an screen are present. In other words, whetherterm.read
andterm.write
will actually do something. -
term.getCursor(): number, number
Gets the current position of the cursor. -
term.setCursor(col: number, row: number)
Sets the cursor position to the specified coordinates. -
term.getCursorBlink(): boolean
Gets whether the cursor blink is currently enabled, i.e whether the cursor alternates between the actual "pixel" displayed at the cursor position and a fully white block every half second. -
term.setCursorBlink(enabled: boolean)
Sets whether cursor blink should be enabled or not. -
term.clear()
Clears the complete screen and resets the cursor position to (1, 1). -
term.clearLine()
Clears the line the cursor is currently on and resets the cursor's horizontal position to 1. -
term.read([history: table]): string
Read some text from the terminal, i.e. allow the user to input some text. For example, this is used by the shell and Lua interpreter to read user input. This will make the rest of the current line, starting at the current cursor position, an editable area. It allows input, deletion and navigating to the left and right via the arrow keys and home/end keys.
The optionalhistory
table can be used to provide predefined text that can be cycled through via the up and down arrow keys. It must be a sequence (i.e. the keys must be a gap-less integral interval starting at 1). This is used for the command history in shell and Lua interpreter, for example. If text is entered and confirmed with enter, it will be added to the end of this table.
The function will return a string if input was successful, ornil
if there was no more input (user pressed Ctrl+D or Ctrl+C or the terminal became unavailable).
Note:io.stdin:read()
uses this function.
Note 2: This will return the entered string with the \n (new line character). If you want only the entered string to be returned, useio.read()
. -
term.write(value: string[, wrap: boolean])
Allows writing optionally wrapped text to the terminal starting at the current cursor position, updating the cursor accordingly. It automatically converts tab characters to spaces usingtext.detab
. Ifwrap
is true, it will automatically word-wrap the text. It will scroll the displayed buffer if the cursor exceeds the bottom of the display area, but not if it exceeds the right of the display area (whenwrap
is false).
Note:io.stdout:write()
uses this function.