term

The Terminal API provides functions for writing text to the terminal and monitors, and drawing ASCII graphics.

blit(text, textColour, backgroundColour)Writes text to the terminal with the specific foreground and background characters.
setCursorPos(x, y)Set the position of the cursor.
clearLine()Clears the line the cursor is currently on, filling it with the current background colour.
setCursorBlink(blink)Sets whether the cursor should be visible (and blinking) at the current cursor position.
nativePaletteColour(colour)Get the default palette value for a colour.
nativePaletteColor(colour)Get the default palette value for a colour.
setBackgroundColour(colourArg)Set the current background colour.
setBackgroundColor(colourArg)Set the current background colour.
getSize()Get the size of the terminal.
getCursorBlink()Checks if the cursor is currently blinking.
getTextColour()Return the colour that new text will be written as.
getTextColor()Return the colour that new text will be written as.
setPaletteColour(...)Set the palette for a specific colour.
setPaletteColor(...)Set the palette for a specific colour.
setTextColour(colourArg)Set the colour that new text will be written as.
setTextColor(colourArg)Set the colour that new text will be written as.
scroll(y)Move all positions up (or down) by y pixels.
getCursorPos()Get the position of the cursor.
getPaletteColour(colourArg)Get the current palette for a specific colour.
getPaletteColor(colourArg)Get the current palette for a specific colour.
getBackgroundColour()Return the current background colour.
getBackgroundColor()Return the current background colour.
clear()Clears the terminal, filling it with the current background colour.
write(text)Write text at the current cursor position, moving the cursor to the end of the text.
isColour()Determine if this terminal supports colour.
isColor()Determine if this terminal supports colour.
redirect(target)Redirects terminal output to a monitor, a window, or any other custom terminal object.
current()Returns the current terminal object of the computer.
native()Get the native terminal object of the current computer.
blit(text, textColour, backgroundColour)Source

Writes text to the terminal with the specific foreground and background characters.

As with write, the text will be written at the current cursor location, with the cursor moving to the end of the text.

textColour and backgroundColour must both be strings the same length as text. All characters represent a single hexadecimal digit, which is converted to one of CC's colours. For instance, "a" corresponds to purple.

Parameters

  1. text string The text to write.
  2. textColour string The corresponding text colours.
  3. backgroundColour string The corresponding background colours.

Throws

  • If the three inputs are not the same length.

Usage

  • Prints "Hello, world!" in rainbow text.

     term.blit("Hello, world!","01234456789ab","0000000000000")
     

See also

  • colors For a list of colour constants, and their hexadecimal values.
setCursorPos(x, y)Source

Set the position of the cursor. terminal writes will begin from this position.

Parameters

  1. x number The new x position of the cursor.
  2. y number The new y position of the cursor.
clearLine()Source

Clears the line the cursor is currently on, filling it with the current background colour.

setCursorBlink(blink)Source

Sets whether the cursor should be visible (and blinking) at the current cursor position.

Parameters

  1. blink boolean Whether the cursor should blink.
nativePaletteColour(colour)Source

Get the default palette value for a colour.

Parameters

  1. colour number The colour whose palette should be fetched.

Returns

  1. number The red channel, will be between 0 and 1.
  2. number The green channel, will be between 0 and 1.
  3. number The blue channel, will be between 0 and 1.

Throws

  • When given an invalid colour.

See also

nativePaletteColor(colour)Source

Get the default palette value for a colour.

Parameters

  1. colour number The colour whose palette should be fetched.

Returns

  1. number The red channel, will be between 0 and 1.
  2. number The green channel, will be between 0 and 1.
  3. number The blue channel, will be between 0 and 1.

Throws

  • When given an invalid colour.

See also

setBackgroundColour(colourArg)Source

Set the current background colour. This is used when writing text and clearing the terminal.

Parameters

  1. colourArg number The new background colour.

See also

  • colors For a list of colour constants.
setBackgroundColor(colourArg)Source

Set the current background colour. This is used when writing text and clearing the terminal.

Parameters

  1. colourArg number The new background colour.

See also

  • colors For a list of colour constants.
getSize()Source

Get the size of the terminal.

Returns

  1. number The terminal's width.
  2. number The terminal's height.
getCursorBlink()Source

Checks if the cursor is currently blinking.

Returns

  1. boolean If the cursor is blinking.
getTextColour()Source

Return the colour that new text will be written as.

Returns

  1. number The current text colour.

See also

  • colors For a list of colour constants, returned by this function.
getTextColor()Source

Return the colour that new text will be written as.

Returns

  1. number The current text colour.

See also

  • colors For a list of colour constants, returned by this function.
setPaletteColour(...)Source

Set the palette for a specific colour.

ComputerCraft's palette system allows you to change how a specific colour should be displayed. For instance, you can make colors.red more red by setting its palette to #FF0000. This does now allow you to draw more colours - you are still limited to 16 on the screen at one time - but you can change which colours are used.

Parameters

  1. index number The colour whose palette should be changed.
  2. colour number A 24-bit integer representing the RGB value of the colour. For instance the integer 0xFF0000 corresponds to the colour #FF0000.

Or

  1. index number The colour whose palette should be changed.
  2. r number The intensity of the red channel, between 0 and 1.
  3. g number The intensity of the green channel, between 0 and 1.
  4. b number The intensity of the blue channel, between 0 and 1.

Usage

  • Change the red colour from the default #CC4C4C to #FF0000.

     term.setPaletteColour(colors.red, 0xFF0000)
     term.setTextColour(colors.red)
     print("Hello, world!")
     
  • As above, but specifying each colour channel separately.

     term.setPaletteColour(colors.red, 1, 0, 0)
     term.setTextColour(colors.red)
     print("Hello, world!")
     

See also

  • colors.unpackRGB To convert from the 24-bit format to three separate channels.
  • colors.packRGB To convert from three separate channels to the 24-bit format.
setPaletteColor(...)Source

Set the palette for a specific colour.

ComputerCraft's palette system allows you to change how a specific colour should be displayed. For instance, you can make colors.red more red by setting its palette to #FF0000. This does now allow you to draw more colours - you are still limited to 16 on the screen at one time - but you can change which colours are used.

Parameters

  1. index number The colour whose palette should be changed.
  2. colour number A 24-bit integer representing the RGB value of the colour. For instance the integer 0xFF0000 corresponds to the colour #FF0000.

Or

  1. index number The colour whose palette should be changed.
  2. r number The intensity of the red channel, between 0 and 1.
  3. g number The intensity of the green channel, between 0 and 1.
  4. b number The intensity of the blue channel, between 0 and 1.

Usage

  • Change the red colour from the default #CC4C4C to #FF0000.

     term.setPaletteColour(colors.red, 0xFF0000)
     term.setTextColour(colors.red)
     print("Hello, world!")
     
  • As above, but specifying each colour channel separately.

     term.setPaletteColour(colors.red, 1, 0, 0)
     term.setTextColour(colors.red)
     print("Hello, world!")
     

See also

  • colors.unpackRGB To convert from the 24-bit format to three separate channels.
  • colors.packRGB To convert from three separate channels to the 24-bit format.
setTextColour(colourArg)Source

Set the colour that new text will be written as.

Parameters

  1. colourArg number The new text colour.

See also

  • colors For a list of colour constants.
setTextColor(colourArg)Source

Set the colour that new text will be written as.

Parameters

  1. colourArg number The new text colour.

See also

  • colors For a list of colour constants.
scroll(y)Source

Move all positions up (or down) by y pixels.

Every pixel in the terminal will be replaced by the line y pixels below it. If y is negative, it will copy pixels from above instead.

Parameters

  1. y number The number of lines to move up by. This may be a negative number.
getCursorPos()Source

Get the position of the cursor.

Returns

  1. number The x position of the cursor.
  2. number The y position of the cursor.
getPaletteColour(colourArg)Source

Get the current palette for a specific colour.

Parameters

  1. colourArg number The colour whose palette should be fetched.

Returns

  1. number The red channel, will be between 0 and 1.
  2. number The green channel, will be between 0 and 1.
  3. number The blue channel, will be between 0 and 1.
getPaletteColor(colourArg)Source

Get the current palette for a specific colour.

Parameters

  1. colourArg number The colour whose palette should be fetched.

Returns

  1. number The red channel, will be between 0 and 1.
  2. number The green channel, will be between 0 and 1.
  3. number The blue channel, will be between 0 and 1.
getBackgroundColour()Source

Return the current background colour. This is used when writing text and clearing the terminal.

Returns

  1. number The current background colour.

See also

  • colors For a list of colour constants, returned by this function.
getBackgroundColor()Source

Return the current background colour. This is used when writing text and clearing the terminal.

Returns

  1. number The current background colour.

See also

  • colors For a list of colour constants, returned by this function.
clear()Source

Clears the terminal, filling it with the current background colour.

write(text)Source

Write text at the current cursor position, moving the cursor to the end of the text.

Unlike functions like write and print, this does not wrap the text - it simply copies the text to the current terminal line.

Parameters

  1. text The text to write.
isColour()Source

Determine if this terminal supports colour.

Terminals which do not support colour will still allow writing coloured text/backgrounds, but it will be displayed in greyscale.

Returns

  1. boolean Whether this terminal supports colour.
isColor()Source

Determine if this terminal supports colour.

Terminals which do not support colour will still allow writing coloured text/backgrounds, but it will be displayed in greyscale.

Returns

  1. boolean Whether this terminal supports colour.
redirect(target)Source

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 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).

Parameters

  1. target Redirect The terminal redirect the term API will draw to.

Returns

  1. Redirect The previous redirect object, as returned by term.current.

Usage

  • Redirect to a monitor on the right of the computer.

    term.redirect(peripheral.wrap("right"))
current()Source

Returns the current terminal object of the computer.

Returns

  1. Redirect The current terminal redirect

Usage

  • Create a new window which draws to the current redirect target

    window.create(term.current(), 1, 1, 10, 10)
native()Source

Get the native terminal object of the current computer.

It is recommended you do not use this function unless you absolutely have to. In a multitasked environment, term.native will not be the current terminal object, and so drawing may interfere with other programs.

Returns

  1. Redirect The native terminal redirect.

Types

Redirect

A base class for all objects which interact with a terminal. Namely the term and monitors.

Redirect.blit(text, textColour, backgroundColour)Source

Writes text to the terminal with the specific foreground and background characters.

As with write, the text will be written at the current cursor location, with the cursor moving to the end of the text.

textColour and backgroundColour must both be strings the same length as text. All characters represent a single hexadecimal digit, which is converted to one of CC's colours. For instance, "a" corresponds to purple.

Parameters

  1. text string The text to write.
  2. textColour string The corresponding text colours.
  3. backgroundColour string The corresponding background colours.

Throws

  • If the three inputs are not the same length.

Usage

  • Prints "Hello, world!" in rainbow text.

     term.blit("Hello, world!","01234456789ab","0000000000000")
     

See also

  • colors For a list of colour constants, and their hexadecimal values.
Redirect.setCursorPos(x, y)Source

Set the position of the cursor. terminal writes will begin from this position.

Parameters

  1. x number The new x position of the cursor.
  2. y number The new y position of the cursor.
Redirect.clearLine()Source

Clears the line the cursor is currently on, filling it with the current background colour.

Redirect.setCursorBlink(blink)Source

Sets whether the cursor should be visible (and blinking) at the current cursor position.

Parameters

  1. blink boolean Whether the cursor should blink.
Redirect.setBackgroundColour(colourArg)Source

Set the current background colour. This is used when writing text and clearing the terminal.

Parameters

  1. colourArg number The new background colour.

See also

  • colors For a list of colour constants.
Redirect.setBackgroundColor(colourArg)Source

Set the current background colour. This is used when writing text and clearing the terminal.

Parameters

  1. colourArg number The new background colour.

See also

  • colors For a list of colour constants.
Redirect.getSize()Source

Get the size of the terminal.

Returns

  1. number The terminal's width.
  2. number The terminal's height.
Redirect.getCursorBlink()Source

Checks if the cursor is currently blinking.

Returns

  1. boolean If the cursor is blinking.
Redirect.getTextColour()Source

Return the colour that new text will be written as.

Returns

  1. number The current text colour.

See also

  • colors For a list of colour constants, returned by this function.
Redirect.getTextColor()Source

Return the colour that new text will be written as.

Returns

  1. number The current text colour.

See also

  • colors For a list of colour constants, returned by this function.
Redirect.setPaletteColour(...)Source

Set the palette for a specific colour.

ComputerCraft's palette system allows you to change how a specific colour should be displayed. For instance, you can make colors.red more red by setting its palette to #FF0000. This does now allow you to draw more colours - you are still limited to 16 on the screen at one time - but you can change which colours are used.

Parameters

  1. index number The colour whose palette should be changed.
  2. colour number A 24-bit integer representing the RGB value of the colour. For instance the integer 0xFF0000 corresponds to the colour #FF0000.

Or

  1. index number The colour whose palette should be changed.
  2. r number The intensity of the red channel, between 0 and 1.
  3. g number The intensity of the green channel, between 0 and 1.
  4. b number The intensity of the blue channel, between 0 and 1.

Usage

  • Change the red colour from the default #CC4C4C to #FF0000.

     term.setPaletteColour(colors.red, 0xFF0000)
     term.setTextColour(colors.red)
     print("Hello, world!")
     
  • As above, but specifying each colour channel separately.

     term.setPaletteColour(colors.red, 1, 0, 0)
     term.setTextColour(colors.red)
     print("Hello, world!")
     

See also

  • colors.unpackRGB To convert from the 24-bit format to three separate channels.
  • colors.packRGB To convert from three separate channels to the 24-bit format.
Redirect.setPaletteColor(...)Source

Set the palette for a specific colour.

ComputerCraft's palette system allows you to change how a specific colour should be displayed. For instance, you can make colors.red more red by setting its palette to #FF0000. This does now allow you to draw more colours - you are still limited to 16 on the screen at one time - but you can change which colours are used.

Parameters

  1. index number The colour whose palette should be changed.
  2. colour number A 24-bit integer representing the RGB value of the colour. For instance the integer 0xFF0000 corresponds to the colour #FF0000.

Or

  1. index number The colour whose palette should be changed.
  2. r number The intensity of the red channel, between 0 and 1.
  3. g number The intensity of the green channel, between 0 and 1.
  4. b number The intensity of the blue channel, between 0 and 1.

Usage

  • Change the red colour from the default #CC4C4C to #FF0000.

     term.setPaletteColour(colors.red, 0xFF0000)
     term.setTextColour(colors.red)
     print("Hello, world!")
     
  • As above, but specifying each colour channel separately.

     term.setPaletteColour(colors.red, 1, 0, 0)
     term.setTextColour(colors.red)
     print("Hello, world!")
     

See also

  • colors.unpackRGB To convert from the 24-bit format to three separate channels.
  • colors.packRGB To convert from three separate channels to the 24-bit format.
Redirect.setTextColour(colourArg)Source

Set the colour that new text will be written as.

Parameters

  1. colourArg number The new text colour.

See also

  • colors For a list of colour constants.
Redirect.setTextColor(colourArg)Source

Set the colour that new text will be written as.

Parameters

  1. colourArg number The new text colour.

See also

  • colors For a list of colour constants.
Redirect.scroll(y)Source

Move all positions up (or down) by y pixels.

Every pixel in the terminal will be replaced by the line y pixels below it. If y is negative, it will copy pixels from above instead.

Parameters

  1. y number The number of lines to move up by. This may be a negative number.
Redirect.getCursorPos()Source

Get the position of the cursor.

Returns

  1. number The x position of the cursor.
  2. number The y position of the cursor.
Redirect.getPaletteColour(colourArg)Source

Get the current palette for a specific colour.

Parameters

  1. colourArg number The colour whose palette should be fetched.

Returns

  1. number The red channel, will be between 0 and 1.
  2. number The green channel, will be between 0 and 1.
  3. number The blue channel, will be between 0 and 1.
Redirect.getPaletteColor(colourArg)Source

Get the current palette for a specific colour.

Parameters

  1. colourArg number The colour whose palette should be fetched.

Returns

  1. number The red channel, will be between 0 and 1.
  2. number The green channel, will be between 0 and 1.
  3. number The blue channel, will be between 0 and 1.
Redirect.getBackgroundColour()Source

Return the current background colour. This is used when writing text and clearing the terminal.

Returns

  1. number The current background colour.

See also

  • colors For a list of colour constants, returned by this function.
Redirect.getBackgroundColor()Source

Return the current background colour. This is used when writing text and clearing the terminal.

Returns

  1. number The current background colour.

See also

  • colors For a list of colour constants, returned by this function.
Redirect.clear()Source

Clears the terminal, filling it with the current background colour.

Redirect.write(text)Source

Write text at the current cursor position, moving the cursor to the end of the text.

Unlike functions like write and print, this does not wrap the text - it simply copies the text to the current terminal line.

Parameters

  1. text The text to write.
Redirect.isColour()Source

Determine if this terminal supports colour.

Terminals which do not support colour will still allow writing coloured text/backgrounds, but it will be displayed in greyscale.

Returns

  1. boolean Whether this terminal supports colour.
Redirect.isColor()Source

Determine if this terminal supports colour.

Terminals which do not support colour will still allow writing coloured text/backgrounds, but it will be displayed in greyscale.

Returns

  1. boolean Whether this terminal supports colour.