### Manual Installation (Linux/macOS) Source: https://docs.godot-xterm.nix.nz/en/latest/_sources/getting_started/installation.md.txt Use this command to extract the GodotXterm addon files into your Godot project directory on Linux or macOS. ```bash unzip godot-xterm-v4.0.0.zip -d /path/to/your/project ``` -------------------------------- ### open Source: https://docs.godot-xterm.nix.nz/en/latest/classes/class_pty.html Opens a pseudoterminal without starting a process. ```APIDOC ## open ### Description Opens a pseudoterminal without starting a process. This creates the PTY device files for manual interaction. `cols` and `rows` set the initial terminal dimensions. Returns @GlobalScope.OK on success, or an Error code on failure. Useful for setting up a PTY for later use or direct terminal device interaction. ### Method `Error open(cols: int = 80, rows: int = 24)` ### Parameters #### Path Parameters - **cols** (int) - Optional - The initial number of columns for the terminal. Defaults to 80. - **rows** (int) - Optional - The initial number of rows for the terminal. Defaults to 24. ``` -------------------------------- ### fork Source: https://docs.godot-xterm.nix.nz/en/latest/classes/class_pty.html Opens a pseudoterminal and starts a new process. Defaults to the SHELL environment variable if no file is specified. ```APIDOC ## fork ### Description Opens a pseudoterminal and starts a new process using the specified program. `file` defaults to the `SHELL` environment variable, or platform defaults if not set: `sh` on Linux, `zsh` on macOS, or `cmd.exe` on Windows. `args` are arguments passed to the program. `cwd` is the working directory (defaults to current directory). `cols` and `rows` set the initial terminal dimensions. Returns @GlobalScope.OK on success, or an Error code on failure. ### Method `Error fork(file: String = "", args: PackedStringArray = PackedStringArray(), cwd: String = ".", cols: int = 80, rows: int = 24)` ### Parameters #### Path Parameters - **file** (String) - Optional - The program to execute. Defaults to the SHELL environment variable or platform default. - **args** (PackedStringArray) - Optional - Arguments to pass to the program. - **cwd** (String) - Optional - The working directory for the new process. Defaults to the current directory. - **cols** (int) - Optional - The initial number of columns for the terminal. Defaults to 80. - **rows** (int) - Optional - The initial number of rows for the terminal. Defaults to 24. ### Request Example ```gdscript # Fork a default shell var result = pty.fork() if result == OK: print("Shell started successfully") # Fork a specific program with arguments var result = pty.fork("python3", ["-i"], "/home/user") # Fork with custom terminal size var result = pty.fork("bash", [], ".", 120, 40) ``` ``` -------------------------------- ### Opening a PTY Manually Source: https://docs.godot-xterm.nix.nz/en/latest/classes/class_pty.html Use `open()` to create a pseudoterminal without starting a process. This is useful for manual PTY setup or direct device interaction. Initial dimensions can be specified. ```GDScript var result = pty.open(80, 24) if result == OK: print("PTY opened successfully") ``` -------------------------------- ### Clean Build Artifacts Source: https://docs.godot-xterm.nix.nz/en/latest/_sources/development/building_from_source.md.txt Run this command to remove all generated build artifacts. This is useful for starting a clean build or freeing up disk space. ```bash just clean ``` -------------------------------- ### Forking a Shell Process Source: https://docs.godot-xterm.nix.nz/en/latest/classes/class_pty.html Use `fork()` to start a new process. It defaults to the system's shell if no file is specified. You can provide arguments, a working directory, and initial terminal dimensions. ```GDScript # Fork a default shell var result = pty.fork() if result == OK: print("Shell started successfully") # Fork a specific program with arguments var result = pty.fork("python3", ["-i"], "/home/user") # Fork with custom terminal size var result = pty.fork("bash", [], ".", 120, 40) ``` -------------------------------- ### Basic Terminal Usage in GDScript Source: https://docs.godot-xterm.nix.nz/en/latest/_sources/getting_started/terminal_node.md.txt Demonstrates essential methods for writing text, handling colored text with ANSI escape sequences, getting terminal dimensions, and clearing the terminal. ```gdscript 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() ``` -------------------------------- ### Stream Output from a Long-Running Process Source: https://docs.godot-xterm.nix.nz/en/latest/getting_started/pty_node.html Starts a long-running process (e.g., 'ping'), streams its output, and terminates it after a delay using SIGINT. ```gdscript extends Node @onready var pty = $PTY func _ready(): # Connect to signals pty.data_received.connect(_on_output) pty.exited.connect(_on_exit) # Start ping var result = pty.fork("ping", ["google.com"]) if result != OK: print("Failed to start ping: ", result) return # Stop ping after 10 seconds await get_tree().create_timer(10.0).timeout print("Stopping ping...") pty.kill(2) # Send SIGINT to stop the process func _on_output(data: PackedByteArray): var output = data.get_string_from_utf8() print("Shell output: ", output) func _on_exit(exit_code: int, signal_code: int): print("Shell exited with code: ", exit_code) ``` -------------------------------- ### Stream Output from a Long-Running Process Source: https://docs.godot-xterm.nix.nz/en/latest/_sources/getting_started/pty_node.md.txt Start a long-running process like 'ping' and terminate it after a delay using a signal like SIGINT. This demonstrates real-time output streaming and process control. ```gdscript extends Node @onready var pty = $PTY func _ready(): # Connect to signals pty.data_received.connect(_on_output) pty.exited.connect(_on_exit) # Start ping var result = pty.fork("ping", ["google.com"]) if result != OK: print("Failed to start ping: ", result) return # Stop ping after 10 seconds await get_tree().create_timer(10.0).timeout print("Stopping ping...") pty.kill(2) # Send SIGINT to stop the process func _on_output(data: PackedByteArray): var output = data.get_string_from_utf8() print("Shell output: ", output) func _on_exit(exit_code: int, signal_code: int): print("Shell exited with code: ", exit_code) ``` -------------------------------- ### Get Terminal Width (Columns) Source: https://docs.godot-xterm.nix.nz/en/latest/classes/class_terminal.html Returns the current width of the terminal in characters. This value updates automatically when the terminal is resized. ```gdscript var cols = terminal.get_cols() ``` -------------------------------- ### select Source: https://docs.godot-xterm.nix.nz/en/latest/classes/class_terminal.html Selects text from one position to another in the terminal. `from_line` and `from_column` specify the starting position of the selection. `to_line` and `to_column` specify the ending position of the selection. All coordinates are zero-based. The selected text will typically be highlighted, and can be copied using copy_selection(). ```APIDOC ## select ### Description Selects text within the terminal. ### Method POST ### Endpoint `/terminal/select` ### Parameters #### Request Body - **from_line** (int) - Required - The starting line of the selection. - **from_column** (int) - Required - The starting column of the selection. - **to_line** (int) - Required - The ending line of the selection. - **to_column** (int) - Required - The ending column of the selection. ``` -------------------------------- ### Get Terminal Height (Rows) Source: https://docs.godot-xterm.nix.nz/en/latest/classes/class_terminal.html Returns the current height of the terminal in characters (rows). This value updates automatically when the terminal is resized. ```gdscript var rows = terminal.get_rows() ``` -------------------------------- ### Get Terminal Cursor Position Source: https://docs.godot-xterm.nix.nz/en/latest/classes/class_terminal.html Returns the current cursor position as a Vector2i, with x representing the column and y representing the row. Both are zero-based. ```gdscript var cursor_pos = terminal.get_cursor_pos() ``` -------------------------------- ### Get Terminal Cell Size Source: https://docs.godot-xterm.nix.nz/en/latest/classes/class_terminal.html Retrieves the size of a single character cell in pixels, based on the current font. Useful for precise layout calculations. ```gdscript var cell_size = terminal.get_cell_size() ``` -------------------------------- ### Getting PTY Device Name Source: https://docs.godot-xterm.nix.nz/en/latest/classes/class_pty.html Retrieve the pseudoterminal device name using `get_pts_name()`. This is useful for identifying the PTY on Unix-like systems. Returns an empty string if no PTY is open or on platforms without traditional PTY device files. ```GDScript var pts_name = pty.get_pts_name() if pts_name != "": print("PTY device: ", pts_name) ``` -------------------------------- ### Build All Targets (Including JavaScript) Source: https://docs.godot-xterm.nix.nz/en/latest/_sources/development/building_from_source.md.txt Execute this command to build all available targets, including the JavaScript/WebAssembly build. This ensures all platform compatibility. ```bash just build-all ``` -------------------------------- ### Run All Tests Source: https://docs.godot-xterm.nix.nz/en/latest/_sources/development/building_from_source.md.txt After building, execute this command to run all available tests, including unit, integration, and visual tests. This verifies the integrity of your build. ```bash just test ``` -------------------------------- ### Build JavaScript/Web Target Source: https://docs.godot-xterm.nix.nz/en/latest/_sources/development/building_from_source.md.txt Building for the web requires Docker. This command uses a Docker container to cross-compile the extension to WebAssembly. ```bash just build-javascript ``` -------------------------------- ### Build Native Extension (Debug) Source: https://docs.godot-xterm.nix.nz/en/latest/_sources/development/building_from_source.md.txt Use this command to build the native extension in debug mode. This is the default build target. ```bash just build ``` -------------------------------- ### Build with Release Target Source: https://docs.godot-xterm.nix.nz/en/latest/_sources/development/building_from_source.md.txt To create a release build, set the TARGET environment variable to 'release' before running the build command. Release builds are optimized for performance and size. ```bash TARGET=release just build ``` -------------------------------- ### Run Specific Test Types Source: https://docs.godot-xterm.nix.nz/en/latest/_sources/development/building_from_source.md.txt You can run specific types of tests by providing the test type as an argument to the 'just test' command. Available types include 'unit', 'integration', and 'visual'. ```bash just test unit ``` ```bash just test integration ``` ```bash just test visual ``` -------------------------------- ### copy_all() Source: https://docs.godot-xterm.nix.nz/en/latest/classes/class_terminal.html Copies all of the text in the terminal, including the scrollback buffer, and returns it as a string. ```APIDOC ## copy_all() ### Description Copies all of the text in the terminal, including the scrollback buffer. Returns the complete terminal content as a string with newlines separating rows. ### Method `String copy_all()` ### Request Example ```gdscript var terminal_content = terminal.copy_all() print("Terminal contains: ", terminal_content) ``` ``` -------------------------------- ### Run a Simple Command with PTY Source: https://docs.godot-xterm.nix.nz/en/latest/getting_started/pty_node.html Connects to PTY signals and runs a simple command like 'ls -la'. Output and exit status are handled via signals. ```gdscript extends Node @onready var pty = $PTY func _ready(): # Connect to signals pty.data_received.connect(_on_output) pty.exited.connect(_on_exit) # Run a simple command var result = pty.fork("ls", ["-la"]) if result != OK: print("Failed to run command: ", result) func _on_output(data: PackedByteArray): var output = data.get_string_from_utf8() print("Command output: ", output) func _on_exit(exit_code: int, signal_code: int): print("Command finished with exit code: ", exit_code) ``` -------------------------------- ### Run a Simple Command with PTY Source: https://docs.godot-xterm.nix.nz/en/latest/_sources/getting_started/pty_node.md.txt Connect to PTY signals and run a simple command like 'ls -la'. Output is received via the 'data_received' signal and the process exit is handled by the 'exited' signal. ```gdscript extends Node @onready var pty = $PTY func _ready(): # Connect to signals pty.data_received.connect(_on_output) pty.exited.connect(_on_exit) # Run a simple command var result = pty.fork("ls", ["-la"]) if result != OK: print("Failed to run command: ", result) func _on_output(data: PackedByteArray): var output = data.get_string_from_utf8() print("Command output: ", output) func _on_exit(exit_code: int, signal_code: int): print("Command finished with exit code: ", exit_code) ``` -------------------------------- ### Connecting Terminal Signals in GDScript Source: https://docs.godot-xterm.nix.nz/en/latest/_sources/getting_started/terminal_node.md.txt Shows how to connect to and handle signals emitted by the Terminal node, including data sent by the user, terminal bell, and size changes. ```gdscript func _ready(): # Connect to terminal signals terminal.data_sent.connect(_on_terminal_data_sent) terminal.bell.connect(_on_terminal_bell) terminal.size_changed.connect(_on_terminal_size_changed) func _on_terminal_data_sent(data: PackedByteArray): # User typed something - data contains the key sequence print("User input: ", data.get_string_from_utf8()) func _on_terminal_bell(): # Terminal bell was triggered print("Ding!") func _on_terminal_size_changed(new_size: Vector2i): # Terminal was resized print("New size: %d cols x %d rows" % [new_size.x, new_size.y]) ``` -------------------------------- ### Terminal Signal Handling Source: https://docs.godot-xterm.nix.nz/en/latest/getting_started/terminal_node.html Shows how to connect to and handle terminal signals for user input, bell events, and size changes. ```gdscript func _ready(): # Connect to terminal signals terminal.data_sent.connect(_on_terminal_data_sent) terminal.bell.connect(_on_terminal_bell) terminal.size_changed.connect(_on_terminal_size_changed) func _on_terminal_data_sent(data: PackedByteArray): # User typed something - data contains the key sequence print("User input: ", data.get_string_from_utf8()) func _on_terminal_bell(): # Terminal bell was triggered print("Ding!") func _on_terminal_size_changed(new_size: Vector2i): # Terminal was resized print("New size: %d cols x %d rows" % [new_size.x, new_size.y]) ``` -------------------------------- ### resizev Source: https://docs.godot-xterm.nix.nz/en/latest/classes/class_pty.html Resizes the pseudoterminal using a Vector2i. ```APIDOC ## resizev ### Description Same as resize(), but accepts a Vector2i where `x` is columns and `y` is rows. Convenience method for when you have the terminal size as a vector. ### Method `void resizev(size: Vector2i)` ### Parameters #### Path Parameters - **size** (Vector2i) - Required - A Vector2i where x represents columns and y represents rows. ``` -------------------------------- ### PTY Class Methods Source: https://docs.godot-xterm.nix.nz/en/latest/classes/class_pty.html This section details the methods available for interacting with the PTY class, including process management, communication, and resizing. ```APIDOC ## PTY Class Methods ### fork Starts a new process and connects it to the PTY. **Parameters** - `file` (String): The executable file to run. Defaults to "". - `args` (PackedStringArray): Arguments to pass to the executable. Defaults to an empty array. - `cwd` (String): The current working directory for the process. Defaults to ".". - `cols` (int): The initial number of columns for the PTY. Defaults to `80`. - `rows` (int): The initial number of rows for the PTY. Defaults to `24`. **Returns** - `Error`: An error code indicating the success or failure of the operation. ### get_pts_name Returns the name of the pseudoterminal device. **Returns** - `String`: The name of the PTY device. ### kill Sends a signal to the child process. **Parameters** - `signal` (int): The signal to send. Use values from the `IPCSignal` enum. ### open Creates a PTY without starting a process, allowing manual interaction. **Parameters** - `cols` (int): The initial number of columns for the PTY. Defaults to `80`. - `rows` (int): The initial number of rows for the PTY. Defaults to `24`. **Returns** - `Error`: An error code indicating the success or failure of the operation. ### resize Resizes the pseudoterminal to the specified dimensions. **Parameters** - `cols` (int): The new number of columns. - `rows` (int): The new number of rows. ### resizev Resizes the pseudoterminal to the specified size. **Parameters** - `size` (Vector2i): The new size (columns, rows). ### write Writes data to the pseudoterminal. **Parameters** - `data` (Variant): The data to write. Typically a String or PackedByteArray. ``` -------------------------------- ### write Source: https://docs.godot-xterm.nix.nz/en/latest/classes/class_pty.html Writes data to the pseudoterminal's standard input. ```APIDOC ## write ### Description Writes data to the pseudoterminal. Accepts either a String or PackedByteArray. This data is sent to the child process’s stdin. For interactive shells, this typically represents user input such as typed commands. ### Method `void write(data: Variant) const` ### Parameters #### Path Parameters - **data** (Variant) - Required - The data to write, can be a String or PackedByteArray. ``` -------------------------------- ### MIT License Text Source: https://docs.godot-xterm.nix.nz/en/latest/about/licenses.html The MIT License governs the use, modification, and distribution of the GodotXterm software. ```text # MIT License Copyright (c) 2020-2025, Leroy Hopson and GodotXterm contributors. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ``` -------------------------------- ### Terminal Methods Source: https://docs.godot-xterm.nix.nz/en/latest/classes/class_terminal.html Methods available for interacting with the Terminal node, such as clearing the screen, copying text, and writing data. ```APIDOC ## Methods - **clear()** - void Clears the terminal screen and resets cursor position. - **copy_all()** - String Copies all text content from the terminal to the clipboard. - **copy_selection()** - String Copies the currently selected text within the terminal to the clipboard. - **get_cell_size() const** - Vector2 Returns the size of a single cell in pixels. - **get_cols() const** - int Returns the current number of columns in the terminal. - **get_cursor_pos() const** - Vector2i Returns the current cursor position (column, row). - **get_rows() const** - int Returns the current number of rows in the terminal. - **select**(from_line: int, from_column: int, to_line: int, to_column: int) - void Selects a rectangular region of text in the terminal. - **write**(data: Variant) - String Writes data to the terminal. This can be plain text or control sequences. ``` -------------------------------- ### write Source: https://docs.godot-xterm.nix.nz/en/latest/classes/class_terminal.html Writes data to the terminal emulator for display. Accepts either a String or PackedByteArray. The data is processed through the terminal state machine, which interprets ANSI escape sequences for colors, cursor movement, and other terminal control functions. Returns any response data that should be sent back (typically for interactive applications). ```APIDOC ## write ### Description Writes data to the terminal emulator. ### Method POST ### Endpoint `/terminal/write` ### Parameters #### Request Body - **data** (String | PackedByteArray) - Required - The data to write to the terminal. ### Request Example ```json { "data": "Hello World\n" } ``` ```json { "data": "\e[31mRed text\e[0m\n" } ``` ```json { "data": "[27, 91, 50, 74]" } ``` ### Response #### Success Response (200) - **response_data** (String) - Any response data to be sent back. ``` -------------------------------- ### resize Source: https://docs.godot-xterm.nix.nz/en/latest/classes/class_pty.html Resizes the pseudoterminal to the specified number of columns and rows. ```APIDOC ## resize ### Description Resizes the pseudoterminal to `cols` columns and `rows` rows. Call this when the connected Terminal node changes size to keep them synchronized. The child process will receive a `SIGWINCH` signal on Unix platforms to notify it of the size change. ### Method `void resize(cols: int, rows: int)` ### Parameters #### Path Parameters - **cols** (int) - Required - The new number of columns. - **rows** (int) - Required - The new number of rows. ``` -------------------------------- ### Writing Data to PTY Source: https://docs.godot-xterm.nix.nz/en/latest/classes/class_pty.html Use `write()` to send data to the child process's standard input. This method accepts String or PackedByteArray and is typically used for sending user input like commands. ```GDScript # Send a command to a shell pty.write("ls -la\n") ``` -------------------------------- ### pty.write Source: https://docs.godot-xterm.nix.nz/en/latest/classes/class_pty.html Sends raw bytes to the pseudo-terminal. This is useful for sending control characters like Ctrl+C. ```APIDOC ## pty.write ### Description Sends raw bytes to the pseudo-terminal. This is useful for sending control characters like Ctrl+C. ### Method `write` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **bytes** (PackedByteArray) - Required - The byte array to send. ### Request Example ```gdscript pty.write(PackedByteArray([0x03])) ``` ### Response #### Success Response (void) This method has no return value. #### Response Example None ``` -------------------------------- ### Send Raw Bytes to PTY Source: https://docs.godot-xterm.nix.nz/en/latest/classes/class_pty.html Use the `write` method to send raw bytes, such as control characters like Ctrl+C, to the pseudo-terminal. This is useful for simulating user input or sending specific commands. ```gdscript pty.write(PackedByteArray([0x03])) ``` -------------------------------- ### copy_selection() Source: https://docs.godot-xterm.nix.nz/en/latest/classes/class_terminal.html Copies only the currently selected (highlighted) text in the terminal. Returns an empty string if no text is selected. ```APIDOC ## copy_selection() ### Description Copies only the currently selected (i.e. highlighted) text in the terminal. Returns an empty string if no text is currently selected. Text can be selected by dragging the mouse or using the select() method. ### Method `String copy_selection()` ``` -------------------------------- ### kill Source: https://docs.godot-xterm.nix.nz/en/latest/classes/class_pty.html Sends a signal to the PTY's child process. ```APIDOC ## kill ### Description Sends a signal to the PTY’s child process. `signal` is the signal number to send. You can use the IPCSignal constants for common signals, or any valid signal number. Note: This method has no effect if no child process is running. ### Method `void kill(signal: int)` ### Parameters #### Path Parameters - **signal** (int) - Required - The signal number to send (e.g., PTY.IPCSIGNAL_SIGTERM). ### Request Example ```gdscript # Send SIGTERM to gracefully terminate the process pty.kill(PTY.IPCSIGNAL_SIGTERM) # Send SIGKILL to forcefully terminate the process pty.kill(PTY.IPCSIGNAL_SIGKILL) # Send SIGINT (equivalent to Ctrl + C) pty.kill(PTY.IPCSIGNAL_SIGINT) ``` ``` -------------------------------- ### Copy All Terminal Content Source: https://docs.godot-xterm.nix.nz/en/latest/classes/class_terminal.html Copies all text from the terminal, including the scrollback buffer, into a single string. Useful for saving or processing the entire terminal output. ```GDScript var terminal_content = terminal.copy_all() print("Terminal contains: ", terminal_content) ``` -------------------------------- ### get_pts_name Source: https://docs.godot-xterm.nix.nz/en/latest/classes/class_pty.html Returns the pseudoterminal device name. ```APIDOC ## get_pts_name ### Description Returns the pseudoterminal device name. On Unix-like systems, this is typically a path like `/dev/pts/1`. Returns an empty string if no PTY is open or on platforms that don’t use traditional PTY device files (such as Windows). ### Method `String get_pts_name() const` ### Response Example ```gdscript var pts_name = pty.get_pts_name() if pts_name != "": print("PTY device: ", pts_name) ``` ``` -------------------------------- ### Resizing PTY Dimensions Source: https://docs.godot-xterm.nix.nz/en/latest/classes/class_pty.html Use `resize()` or `resizev()` to change the pseudoterminal's dimensions. Call this when the connected Terminal node resizes to maintain synchronization. On Unix, this sends a `SIGWINCH` signal to the child process. ```GDScript # Resize using columns and rows pty.resize(120, 40) # Resize using a Vector2i pty.resizev(Vector2i(100, 30)) ``` -------------------------------- ### Sending Signals to Child Process Source: https://docs.godot-xterm.nix.nz/en/latest/classes/class_pty.html Use `kill()` to send signals to the PTY's child process. Common signals like SIGTERM, SIGKILL, and SIGINT can be sent using the `IPCSIGNAL` constants. This method has no effect if no child process is running. ```GDScript # Send SIGTERM to gracefully terminate the process pty.kill(PTY.IPCSIGNAL_SIGTERM) # Send SIGKILL to forcefully terminate the process pty.kill(PTY.IPCSIGNAL_SIGKILL) # Send SIGINT (equivalent to Ctrl + C) pty.kill(PTY.IPCSIGNAL_SIGINT) ``` -------------------------------- ### get_rows Source: https://docs.godot-xterm.nix.nz/en/latest/classes/class_terminal.html Returns the height of the terminal in characters (rows). This represents the number of character rows that can fit vertically in the terminal at the current font size. Automatically updates when the terminal is resized. ```APIDOC ## get_rows ### Description Returns the height of the terminal in characters (rows). ### Method GET ### Endpoint `/terminal/rows` ### Response #### Success Response (200) - **rows** (int) - The height of the terminal in characters. ``` -------------------------------- ### clear() Source: https://docs.godot-xterm.nix.nz/en/latest/classes/class_terminal.html Clears the terminal screen, removing all text except the bottom row and clearing the scrollback buffer. The cursor is moved to the top-left corner. ```APIDOC ## clear() ### Description Clears the terminal screen, removing all text except the bottom row. This also clears the scrollback buffer. The cursor is moved to the top-left corner. Equivalent to sending the ANSI escape sequence `\u001b[2J\u001b[H`. ### Method `void clear()` ``` -------------------------------- ### Select and Copy Text in Terminal Source: https://docs.godot-xterm.nix.nz/en/latest/classes/class_terminal.html Selects a region of text within the terminal and then copies the selected content. Coordinates are zero-based. ```gdscript terminal.select(0, 0, 0, 10) var selected_text = terminal.copy_selection() ``` -------------------------------- ### Terminal Properties Source: https://docs.godot-xterm.nix.nz/en/latest/classes/class_terminal.html Properties that can be set or retrieved for the Terminal node to control its behavior and appearance. ```APIDOC ## Properties - **bell_cooldown** (float) - `0.1` - **bell_muted** (bool) - `false` - **blink_off_time** (float) - `0.3` - **blink_on_time** (float) - `0.6` - **copy_on_selection** (bool) - `false` - **focus_mode** (FocusMode) - `2` (overrides Control) - **inverse_mode** (InverseMode) - `0` - **max_scrollback** (int) - `1000` ``` -------------------------------- ### Write Data to Terminal Source: https://docs.godot-xterm.nix.nz/en/latest/classes/class_terminal.html Writes text or raw bytes to the terminal emulator. Supports ANSI escape sequences for formatting and control. Returns any response data. ```gdscript # Write simple text terminal.write("Hello World\n") # Write colored text using ANSI escape sequences terminal.write("\e[31mRed text\e[0m\n") # Write raw bytes terminal.write(PackedByteArray([0x1b, 0x5b, 0x32, 0x4a])) # Clear screen ``` -------------------------------- ### get_cols Source: https://docs.godot-xterm.nix.nz/en/latest/classes/class_terminal.html Returns the width of the terminal in characters. When using a monospace font, this is the number of visible characters that can fit from one side of the terminal to the other in a single row. It will automatically update according to the terminal’s size. ```APIDOC ## get_cols ### Description Returns the width of the terminal in characters. ### Method GET ### Endpoint `/terminal/cols` ### Response #### Success Response (200) - **cols** (int) - The width of the terminal in characters. ``` -------------------------------- ### Connect PTY to a Terminal Node Source: https://docs.godot-xterm.nix.nz/en/latest/_sources/getting_started/pty_node.md.txt Fork a shell process directly from a Terminal node. Ensure the PTY's 'Terminal Path' inspector property is set to link it to the Terminal node. ```gdscript extends Terminal @onready var pty = $PTY func _ready(): # terminal_path is already set in inspector to connect signals automatically # Fork a shell process var result = pty.fork() if result != OK: print("Failed to start shell: ", result) ``` -------------------------------- ### Fork a Shell Process for a Terminal Node Source: https://docs.godot-xterm.nix.nz/en/latest/getting_started/pty_node.html Forks a default shell process when no arguments are provided to fork(). This is typically used when connecting a PTY node to a Terminal node. ```gdscript extends Terminal @onready var pty = $PTY func _ready(): # terminal_path is already set in inspector to connect signals automatically # Fork a shell process var result = pty.fork() if result != OK: print("Failed to start shell: ", result) ``` -------------------------------- ### get_cursor_pos Source: https://docs.godot-xterm.nix.nz/en/latest/classes/class_terminal.html Returns the current cursor position as a Vector2i where `x` is the column and `y` is the row. Both values are zero-based, so the top-left corner is `Vector2i(0, 0)`. ```APIDOC ## get_cursor_pos ### Description Returns the current cursor position. ### Method GET ### Endpoint `/terminal/cursor_pos` ### Response #### Success Response (200) - **position** (Vector2i) - The cursor position (column, row). ``` -------------------------------- ### PTY Class Enumerations Source: https://docs.godot-xterm.nix.nz/en/latest/classes/class_pty.html This section details the enumerations used within the PTY class, primarily for signal handling. ```APIDOC ## PTY Class Enumerations ### IPCSignal Represents standard Unix signals that can be sent to or received from processes. - **IPCSIGNAL_SIGHUP** (1): Hangup signal. - **IPCSIGNAL_SIGINT** (2): Interrupt signal (Ctrl+C). - **IPCSIGNAL_SIGQUIT** (3): Quit signal (Ctrl+\). - **IPCSIGNAL_SIGILL** (4): Illegal instruction signal. - **IPCSIGNAL_SIGTRAP** (5): Trace/breakpoint trap signal. - **IPCSIGNAL_SIGABRT** (6): Abort signal. - **IPCSIGNAL_SIGFPE** (8): Floating-point exception signal. - **IPCSIGNAL_SIGKILL** (9): Kill signal (cannot be caught). - **IPCSIGNAL_SIGSEGV** (11): Segmentation violation signal. - **IPCSIGNAL_SIGPIPE** (13): Broken pipe signal. - **IPCSIGNAL_SIGALRM** (14): Alarm signal. - **IPCSIGNAL_SIGTERM** (15): Termination signal (graceful termination request). ``` -------------------------------- ### Terminal Enumerations Source: https://docs.godot-xterm.nix.nz/en/latest/classes/class_terminal.html Enumerations used by the Terminal node to define specific modes and behaviors. ```APIDOC ## Enumerations - **InverseMode** - **INVERSE_MODE_INVERT** = `0`: Displays inverse video by inverting foreground and background colors. - **INVERSE_MODE_SWAP** = `1`: Displays inverse video by swapping foreground and background colors. ``` -------------------------------- ### PTY Class Signals Source: https://docs.godot-xterm.nix.nz/en/latest/classes/class_pty.html This section describes the signals emitted by the PTY class, which are used for communication and event handling. ```APIDOC ## PTY Class Signals ### data_received Emitted when data is read from the pseudoterminal. **Parameters** - `data` (PackedByteArray): Raw bytes received from the pseudoterminal, typically stdout or stderr. ### exited Emitted when the child program exits. **Parameters** - `exit_code` (int): The exit status of the child process (0 typically means success). - `signal_code` (int): The signal number that terminated the program, or 0 if the program exited normally. ``` -------------------------------- ### Terminal Signals Source: https://docs.godot-xterm.nix.nz/en/latest/classes/class_terminal.html Signals emitted by the Terminal node to notify about events like bell sounds, data transmission, key presses, and size changes. ```APIDOC ## Signals - **bell**() Emitted when the bell character (`\u0007`) is written to the terminal. Respects `bell_cooldown` and `bell_muted` properties. - **data_sent**(data: PackedByteArray) Emitted when the terminal generates output data, typically in response to user input. This data should be forwarded to a PTY. - **key_pressed**(data: PackedByteArray, event: Object) Emitted when a key is pressed. `data` contains the terminal sequence, and `event` is the original InputEventKey. - **size_changed**(new_size: Vector2i) Emitted when the terminal's size changes. `new_size` contains the new dimensions (columns, rows). This should be forwarded to a connected PTY. ``` -------------------------------- ### get_cell_size Source: https://docs.godot-xterm.nix.nz/en/latest/classes/class_terminal.html Returns the size of a single character cell in pixels. This is determined by the current font size and represents the width and height of one character. Useful for calculating precise positioning and sizing when working with terminal coordinates. ```APIDOC ## get_cell_size ### Description Returns the size of a single character cell in pixels. ### Method GET ### Endpoint `/terminal/cell_size` ### Response #### Success Response (200) - **size** (Vector2) - The width and height of a character cell in pixels. ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.