Difference between revisions of "Term (API)"
From ComputerCraft Wiki
(Updated to API overview v2) |
MKlegoman357 (Talk | contribs) m |
||
(21 intermediate revisions by 8 users not shown) | |||
Line 1: | Line 1: | ||
The Terminal API provides functions for writing text to the terminal and monitors, and drawing ASCII graphics. | The Terminal API provides functions for writing text to the terminal and monitors, and drawing ASCII graphics. | ||
− | + | Functions in ''italics'' are only available to [[Monitor|Monitors]]. Functions in '''bold''' are available only to [[Window (API)|Windows]]. | |
− | + | {{API table|Term|image=Grid disk.png|2= | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | {{API table/row|[[term.write]]({{type|string}} text)|{{type|nil}} | |
+ | |Writes ''text'' to the screen, using the current [[term.setTextColor|text]] and [[term.setBackgroundColor|background colors]].|odd}} | ||
− | + | {{API table/row|[[term.blit]]({{type|string}} text, {{type|string}} text colors, {{type|string}} background colors)|{{type|nil}} | |
− | + | |Writes ''text'' to the screen using the specified text and background colors. ''Requires version 1.74 or newer.''}} | |
− | + | {{API table/row|[[term.clear]]()|{{type|nil}} | |
− | + | |Clears the entire screen.|odd}} | |
− | + | {{API table/row|[[term.clearLine]]()|{{type|nil}} | |
− | + | |Clears the line the cursor is on.}} | |
− | + | {{API table/row|[[term.getCursorPos]]()|{{type|number}} x, {{type|number}} y | |
− | + | |Returns two arguments containing the x and the y position of the cursor.|odd}} | |
− | + | {{API table/row|[[term.setCursorPos]]({{type|number}} x, {{type|number}} y)|{{type|nil}} | |
− | + | |Sets the cursor's position.}} | |
− | + | {{API table/row|[[term.setCursorBlink]]({{type|boolean}} bool)|{{type|nil}} | |
− | + | |Disables the blinking or turns it on.|odd}} | |
− | + | {{API table/row|[[term.isColor]]()|{{type|boolean}} | |
− | + | |Returns whether the terminal supports color.}} | |
− | + | {{API table/row|[[term.getSize]]()|{{type|number}} x, {{type|number}} y | |
− | + | |Returns two arguments containing the x and the y values stating the size of the screen. (Good for if you're making something to be compatible with both [[Turtle]]s and [[Computer]]s.)|odd}} | |
− | + | {{API table/row|[[term.scroll]]({{type|number}} n)|{{type|nil}} | |
− | + | |Scrolls the terminal ''n'' lines.}} | |
− | + | {{API table/row|[[term.redirect]](target)|{{type|table}} previous terminal object | |
− | + | |Redirects terminal output to another terminal object (such as a [[Window (API)|window]] or [[peripheral.wrap|wrapped]] [[monitor]]). ''Available only to the base term object.''|odd}} | |
− | + | {{API table/row|[[term.current]]()|{{type|table}} terminal object | |
− | + | |Returns the current terminal object. ''Requires version 1.6 or newer, available only to the base term object.''}} | |
− | + | {{API table/row|[[term.native]]()|{{type|table}} terminal object | |
− | + | |Returns the original terminal object. ''Requires version 1.6 or newer, available only to the base term object.''|odd}} | |
− | + | {{API table/row|[[term.setTextColor]]({{type|number}} [[Colors (API)|color]])|{{type|nil}} | |
− | + | |Sets the text color of the terminal. ''Limited functionality without an Advanced [[Advanced Computer|Computer]] / [[Advanced Turtle|Turtle]] / [[Advanced Monitor|Monitor]].''}} | |
− | + | ||
+ | {{API table/row|[[term.getTextColor]]()|{{type|number}} color | ||
+ | |Returns the current text color of the terminal. ''Requires version 1.74 or newer.''|odd}} | ||
+ | {{API table/row|[[term.setBackgroundColor]]({{type|number}} [[Colors (API)#Colors|color]])|{{type|nil}} | ||
+ | |Sets the background color of the terminal. ''Limited functionality without an Advanced [[Advanced Computer|Computer]] / [[Advanced Turtle|Turtle]] / [[Advanced Monitor|Monitor]].''}} | ||
+ | |||
+ | {{API table/row|[[term.getBackgroundColor]]()|{{type|number}} color | ||
+ | |Returns the current background color of the terminal. ''Requires version 1.74 or newer.''|odd}} | ||
+ | |||
+ | {{API table/row|''[[monitor.setTextScale]]({{type|number}} scale)''|{{type|nil}} | ||
+ | |Sets the text scale. ''Available only to [[Monitor#Monitor as a Peripheral|monitor]] objects.''}} | ||
+ | |||
+ | {{API table/row|'''[[window.setVisible]]({{type|boolean}} visibility)'''|{{type|nil}} | ||
+ | |Determines whether subsequent renders to the window will be visible. ''Available only to [[Window (API)|window]] objects.''|odd}} | ||
+ | |||
+ | {{API table/row|'''[[window.redraw]]()'''|{{type|nil}} | ||
+ | |Redraws the contents of the window. ''Available only to [[Window (API)|window]] objects.''}} | ||
+ | |||
+ | {{API table/row|'''[[window.restoreCursor]]()'''|{{type|nil}} | ||
+ | |Returns the cursor back to its position / state within the window. ''Available only to [[Window (API)|window]] objects.''|odd}} | ||
+ | |||
+ | {{API table/row|'''[[window.getPosition]]()'''|{{type|number}} x, {{type|number}} y | ||
+ | |Returns the top left co-ordinate of the window. ''Available only to [[Window (API)|window]] objects.''}} | ||
+ | |||
+ | {{API table/row|'''[[window.reposition]]({{type|number}} x, {{type|number}} y [<nowiki/>, {{type|number}} width, {{type|number}} height])'''|{{type|nil}} | ||
+ | |Moves and / or resizes the window. ''Available only to [[Window (API)|window]] objects.''|odd}} | ||
+ | |||
+ | }} | ||
+ | {{Event | ||
+ | |name=[[term_resize (event)|term_resize]] | ||
+ | |desc=Fired when the screen changes size (through opening a new tab with ''bg'', etc). ''Requires version 1.6 or higher.'' | ||
+ | }} | ||
+ | |||
+ | = Deprecated Functions = | ||
+ | {{Deprecated | ||
+ | |plural=yes | ||
+ | |type=These functions | ||
+ | }} | ||
+ | |||
+ | {{API table|Term|image=Grid disk.png|2= | ||
+ | |||
+ | {{API table/row|[[term.restore]]()|{{type|nil}} | ||
+ | |Restores terminal output to the previous target. Removed by ComputerCraft 1.6.|odd}} | ||
+ | |||
+ | }} | ||
[[Category:APIs]] | [[Category:APIs]] |
Latest revision as of 12:27, 28 June 2015
The Terminal API provides functions for writing text to the terminal and monitors, and drawing ASCII graphics.
Functions in italics are only available to Monitors. Functions in bold are available only to Windows.
Term (API) | ||
---|---|---|
Function | Return values | Description |
term.write(string text) | nil | Writes text to the screen, using the current text and background colors. |
term.blit(string text, string text colors, string background colors) | nil | Writes text to the screen using the specified text and background colors. Requires version 1.74 or newer. |
term.clear() | nil | Clears the entire screen. |
term.clearLine() | nil | Clears the line the cursor is on. |
term.getCursorPos() | number x, number y | Returns two arguments containing the x and the y position of the cursor. |
term.setCursorPos(number x, number y) | nil | Sets the cursor's position. |
term.setCursorBlink(boolean bool) | nil | Disables the blinking or turns it on. |
term.isColor() | boolean | Returns whether the terminal supports color. |
term.getSize() | number x, number y | Returns two arguments containing the x and the y values stating the size of the screen. (Good for if you're making something to be compatible with both Turtles and Computers.) |
term.scroll(number n) | nil | Scrolls the terminal n lines. |
term.redirect(target) | table previous terminal object | Redirects terminal output to another terminal object (such as a window or wrapped monitor). Available only to the base term object. |
term.current() | table terminal object | Returns the current terminal object. Requires version 1.6 or newer, available only to the base term object. |
term.native() | table terminal object | Returns the original terminal object. Requires version 1.6 or newer, available only to the base term object. |
term.setTextColor(number color) | nil | Sets the text color of the terminal. Limited functionality without an Advanced Computer / Turtle / Monitor. |
term.getTextColor() | number color | Returns the current text color of the terminal. Requires version 1.74 or newer. |
term.setBackgroundColor(number color) | nil | Sets the background color of the terminal. Limited functionality without an Advanced Computer / Turtle / Monitor. |
term.getBackgroundColor() | number color | Returns the current background color of the terminal. Requires version 1.74 or newer. |
monitor.setTextScale(number scale) | nil | Sets the text scale. Available only to monitor objects. |
window.setVisible(boolean visibility) | nil | Determines whether subsequent renders to the window will be visible. Available only to window objects. |
window.redraw() | nil | Redraws the contents of the window. Available only to window objects. |
window.restoreCursor() | nil | Returns the cursor back to its position / state within the window. Available only to window objects. |
window.getPosition() | number x, number y | Returns the top left co-ordinate of the window. Available only to window objects. |
window.reposition(number x, number y [, number width, number height]) | nil | Moves and / or resizes the window. Available only to window objects. |
Event term_resize | |
Fired when the screen changes size (through opening a new tab with bg, etc). Requires version 1.6 or higher. | |
Returned Object 1 | Nothing |
Deprecated Functions
These functions have been deprecated. These functions have been removed from ComputerCraft .
|
Term (API) | ||
---|---|---|
Function | Return values | Description |
term.restore() | nil | Restores terminal output to the previous target. Removed by ComputerCraft 1.6. |