term.current

From ComputerCraft Wiki
Jump to: navigation, search


Grid Redstone.png  Function term.current
Added by ComputerCraft 1.6, this function returns the current terminal object that is being used to write to; if you intend to redirect elsewhere (eg to an attached Monitor), you may find need to record the identity of the previous object and redirect back to it when done.

Previously, term.restore() could be used to automatically revert back to the previously used output object - ComputerCraft 1.6 also removes that command.
Syntax term.current()
Returns table terminal object
Part of ComputerCraft
API term

Examples

Grid paper.png  Example
Wraps a monitor at the top of the computer, redirects to it, then restores back to the previous display. Uses term.current() if available, or term.restore() if not.
Code
local mon = peripheral.wrap("top")

-- If using a build of ComputerCraft with term.current, record the current terminal output object:
if term.current then mon.restoreTo = term.current() end

-- Redirect the terminal to the attached monitor:
term.redirect(mon)

-- Restore back:
if term.current then
	term.redirect(mon.restoreTo)
else
	term.restore()
end

Additional Notes

  • term.current() requires ComputerCraft version 1.6 or newer.
Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox