Difference between revisions of "Term.redirect"

From ComputerCraft Wiki
Jump to: navigation, search
(More details.)
(Redirecting to term.native() is not a preferred method of reverting.)
Line 6: Line 6:
 
|api=term
 
|api=term
 
|addon=ComputerCraft
 
|addon=ComputerCraft
|desc=Redirects [[term (API)|terminal]] output to a [[monitor]], a [[window (API)|window]], or any custom terminal object. Once the redirect is performed, any calls to a "term" function - or to a function that makes ''use'' of a term function, as as [[print|print()]] - will instead operate with the new terminal object.
+
|desc=Redirects [[term (API)|terminal]] output to a [[monitor]], a [[window (API)|window]], or any other custom terminal object. Once the redirect is performed, any calls to a "term" function - or to a function that makes ''use'' of a term function, as as [[print|print()]] - will instead operate with the new terminal object.
  
 
A "terminal object" is simply a table that contains functions with the same names - and general features - as those found in the [[term (API)|term]] table. For example, a [[Peripheral.wrap|wrapped]] monitor is suitable.
 
A "terminal object" is simply a table that contains functions with the same names - and general features - as those found in the [[term (API)|term]] table. For example, a [[Peripheral.wrap|wrapped]] monitor is suitable.
  
The redirect can be undone by pointing back to [[term.native|term.native()]] (or, for ComputerCraft builds older than 1.6, using [[term.restore|term.restore()]]).
+
The redirect can be undone by pointing back to the previous terminal object (which this function returns whenever you switch). For ComputerCraft builds older than 1.6, use [[term.restore|term.restore()]] to revert instead.
 +
 
 +
Advanced systems running on ComputerCraft 1.6 or later implement [[multishell]], which enables easy multitasking at the expensive of some terminal slow-down (all instances of the [[shell]] are redirected to a [[window (API)|window]], increasing the number of function calls involved in any graphical updates). This can be circumvented by way of redirecting to [[term.native]](), at the cost of (somewhat messily) breaking things for users who actually want the multitasking capability.
  
 
|examples=
 
|examples=
Line 18: Line 20:
 
}}
 
}}
 
{{Example
 
{{Example
|desc=Restores terminal functionality back to the default display (users of ComputerCraft builds older than 1.6 should use [[term.restore|term.restore()]] instead).
+
|desc=Redirects to a monitor, writes some text there, then reverts back to the previous display.
|code=term.redirect(term.native())
+
|code=
 +
local mon = [[peripheral.find]]("monitor")
 +
local oldTerm = term.redirect(mon)
 +
print("I'm written on a monitor!")
 +
term.redirect(oldTerm)
 
}}
 
}}
 
}}
 
}}
  
 
[[Category:API_Functions]]
 
[[Category:API_Functions]]

Revision as of 02:18, 24 August 2015


Grid Redstone.png  Function term.redirect
Redirects terminal output to a monitor, a window, or any other custom terminal object. Once the redirect is performed, any calls to a "term" function - or to a function that makes use of a term function, as as print() - will instead operate with the new terminal object.

A "terminal object" is simply a table that contains functions with the same names - and general features - as those found in the term table. For example, a wrapped monitor is suitable.

The redirect can be undone by pointing back to the previous terminal object (which this function returns whenever you switch). For ComputerCraft builds older than 1.6, use term.restore() to revert instead.

Advanced systems running on ComputerCraft 1.6 or later implement multishell, which enables easy multitasking at the expensive of some terminal slow-down (all instances of the shell are redirected to a window, increasing the number of function calls involved in any graphical updates). This can be circumvented by way of redirecting to term.native(), at the cost of (somewhat messily) breaking things for users who actually want the multitasking capability.
Syntax term.redirect(table terminal object)
Returns table previous terminal object
Part of ComputerCraft
API term

Examples

Grid paper.png  Example
Prints "Hello World!" on the right monitor.
Code
term.redirect(peripheral.wrap("right"))
print("Hello World!")



Grid paper.png  Example
Redirects to a monitor, writes some text there, then reverts back to the previous display.
Code
local mon = peripheral.find("monitor")
local oldTerm = term.redirect(mon)
print("I'm written on a monitor!")
term.redirect(oldTerm)