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
term.read
and term.write
will actually do something.term.getCursor(): number, number
term.setCursor(col: number, row: number)
term.getCursorBlink(): boolean
term.setCursorBlink(enabled: boolean)
term.clear()
term.clearLine()
term.read([history: table[, dobreak:boolean[, hint:table or function[, pwchar:string]]]]): string
history
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.dobreak
parameter, when set to false
(nil
defaults to true
!) will not enter a new line after input was completed (e.g. by the user pressing enter).hint
parameter is used for tab completion. It can either be a table with strings or a function that returns a table of strings and takes two parameters, the current text and the position in that text, i.e. the signature of the callback is function(line:string, pos:number):table
.pwchar
parameter, when given, causes input to be masked using the first char of the given string. For example, providing "*"
will make all entered characters appear as stars. The returned value will still be the actual text inserted, of course.nil
if there was no more input (user pressed Ctrl+D or Ctrl+C or the terminal became unavailable).io.stdin:read()
uses this function.io.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 using text.detab
. If wrap
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 (when wrap
is false).io.stdout:write()
uses this function.