Console#

Introduction#

Use print to display text in the Console in VEXcode IQ (2nd gen) or VS Code.

All new projects begin with the cursor at row 1.

By using print, you can display values to the Console.

Along with normal text and values, print can output special character sequences (escape codes) that change font color or clear the Console.

Note: When using the VEXcode Console, you must connect to the Console Serial Port before any output can be printed to the Console.

Below is a list of available methods:

Actions – Print text to the Console and use Escape Sequences for formatting.

  • print – Prints text to the Console.

  • clear_console – Clears all text from the console.

Mutators – Change the color of text printed to the Console.

Actions#

print#

print displays values on the Console.

Usage:
print(value, end)

Parameters

Description

value

The string (in quotations) or numbers to print to the Console.

end

Optional. By default, Python will add a new line after each print command. To print multiple values to the same line, use the end parameter.

# Print a greeting
print("Hello there!")

# Print text on the same line
print("This text will be ", end="")
print("printed on the same line")

Escape Sequences#

The Console supports escape sequences that can be output via print to change colors or clear the Console. These escape sequences are examples of using print rather than separate API calls.

You can change what color the font will be when printing to the Console by using the following color codes:

  • [31m - Red

  • [32m - Green

  • [34m - Blue

  • [30m - Black

  • [37m - White

  • [33m - Yellow

  • [91m - Orange

  • [35m - Purple

  • [36m - Cyan

  • [97m - Transparent

All color codes need to follow an escape sequence = \033 in order to function.

You can either use this directly with print as a string:

# Print VEXcode in Red to the Console
print("\033[31mVEXcode")

Or, you can use it on its own to set all uses of print afterwards to the set color:

# Set the Console text color to Red before printing
print("\033[31m")
print("VEXcode")

Clear the Console#

By using \033[2J inside of print, you can clear the entire Console. This will also set the cursor back to row 1.

# Clear the Console after 2 seconds
print("VEXcode")
wait(2, SECONDS)
print("\033[2J")

clear_console#

clear_console clears all text from the console.

Usage:
clear_console()

Parameters

Description

This method has no parameters.

# Display text then clear it after two seconds
print("I will be cleared!")
wait(2, SECONDS)
clear_console()

You can also use escape sequences with print to clear the console.

Mutators#

set_console_text_color#

set_console_text_color sets the color for all subsequent console text.

Usage:
set_console_text_color(color)

Parameter

Description

color

The color to set:

  • Color.BLACK
  • Color.BLUE
  • Color.CYAN
  • Color.GREEN
  • Color.ORANGE
  • Color.PURPLE
  • Color.RED
  • Color.WHITE
  • Color.YELLOW.

# Display a green message on the Console
set_console_text_color(GREEN)
print("I am green!")

You can also use escape sequences with print to change the text color.