window.restoreCursor

From ComputerCraft Wiki
Jump to: navigation, search


Grid Redstone.png  Function window.restoreCursor
A function available to window-based terminal objects created via the window API, which restores the cursor to that window.

All windows have parent objects, such as other windows, monitors, or the computer's own display. Rendering to a given child object renders via the parent(s), and hence moves said parent's (one single!) cursor around. If a parent has multiple children, you'll find that they'll fight over that cursor - this command can be used to force it back into the window where you require it, without otherwise affecting that window.

Most actions that can be requested of a window (eg calling its write command, making it visible, etc) will have the same effect.

See also: term.setCursorBlink()
Syntax window.restoreCursor()
Returns None
Part of ComputerCraft
API term

Examples

Grid paper.png  Example
Defines a pair of windows within the current display, each wanting to render the cursor, then switches the control of the cursor between them every couple of seconds (Ctrl + T to exit):
Code
term.clear()

local window1 = window.create(term.current(), 5, 5, 1, 1)
window1.setTextColor(colours.white)
window1.setCursorBlink(true)

local window2 = window.create(term.current(), 10, 5, 1, 1)
window2.setTextColor(colours.black)
window2.setCursorBlink(true)

while true do
	window1.restoreCursor()
	sleep(2)
	
	window2.restoreCursor()
	sleep(2)
end
Output When controlled by window1, the cursor will blink brightly to the left; when controlled by window2, the cursor will blink darkly to the right.