The Terminal node provides a visual terminal emulator in Godot. It can be used standalone to display text and handle ANSI escape sequences, or connected to a PTY for full terminal functionality.
Core Workflow
- User Input: The user types data into the terminal.
- Terminal Output: The terminal processes input (e.g., arrow keys) and emits
data_sent() with the corresponding escape sequence (e.g., "\u001b[B" for the down arrow). - Terminal Input: You can send data to the terminal using the
write() method. - Draw: The terminal interprets the written data (including ANSI sequences) and renders it to the screen.
extends Control
@onready var terminal = $Terminal
func _ready():
# Write text to the terminal
terminal.write("Hello, World!\n")
# Write colored text using ANSI escape sequences
terminal.write("\u001b[31mRed text\u001b[0m\n")
terminal.write("\u001b[32mGreen text\u001b[0m\n")
# Get terminal dimensions
print("Terminal size: %d rows x %d columns" % [terminal.get_rows(), terminal.get_cols()])
# Clear the terminal
terminal.clear()