此API提供了向屏幕输出内容和读取用户输入的简便方法。因此你无需再手动操作GPU API实现这些功能。
term.isAvailable(): boolean
term.read
和term.write
函数能否起到实际作用。term.getViewport(): number, number, number, number, number, number
term.gpu(): table
term.pull([...]): ...
event.pull
的作用完全一致,接收同样的参数,返回同样的结果。此方法用于在等待事件结果时令光标闪烁。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
option
(选项)参数。其索引值被作为histroy
(历史)对待,命名键取代了旧的参数。出于兼容性考虑,OpenOS 1.6仍然支持以前的用法,即参数列表。ops
参数支持新键:nowrap
。term.read
的默认行为(nowrap
为false
)垂直绑定了光标和输入。先前的行为模式下会水平滚动输入,即现在的 term.read({nowrap=true})
。
The optional 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.
The 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).
The 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
.
The 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.
The function will return a string if input was successful, nil
if the pipe was closed (^d), or false
if the pipe was interrupted (^c)
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, use io.read()
.
term.write(value: string[, wrap: boolean])
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).term.write
writes to the same stream as io.stdout
term.bind(gpu)
(new in OpenOS 1.6)
Binds a gpu
proxy (not address) to the terminal. This method is called automatically during boot when the gpu and screen become available. Note that if manually rebinding a terminal to a screen with different width and height, the terminal draw area will be truncated and not maximized. This changes the gpu used in all terminal output, not just via the term api, i.e. io.write
, print
, io.stdout:write
, etc all use the same output stream, and term.bind is used to change the gpu
used.
term.screen(): string
getScreen
on the terminal's bound gpu (see term.bind
)term.keyboard(): string