2022-08-07 12:49:29 +02:00
# PTY
2024-03-29 07:07:43 +01:00
**Inherits:** {{Node}} < {{Object}}
2022-08-07 12:49:29 +02:00
2024-02-12 22:50:19 +01:00
_Linux and macOS only._
2022-08-07 12:49:29 +02:00
Node for forking processes (e.g. bash, nodejs, python) with pseudoterminal file descriptors.
2024-03-29 07:07:43 +01:00
Can be used with the {{Terminal}} node to get an actual shell.
2022-08-07 12:49:29 +02:00
2024-03-29 07:07:43 +01:00
:::{note}
2022-08-07 12:49:29 +02:00
Not currently supported on Windows, but it could be in the future using [ConPTY ](https://docs.microsoft.com/en-us/windows/console ) or [WinPTY ](https://github.com/rprichard/winpty ).
See issue [\#25 ](https://github.com/lihop/godot-xterm/issues/25 ).
2024-03-29 07:07:43 +01:00
:::
2022-08-07 12:49:29 +02:00
## Overview
2024-03-29 07:07:43 +01:00
![PTY Diagram ](../_static/images/diagram_pty.png )
2022-08-07 12:49:29 +02:00
< sub > "PTY Diagram" is a derivative of [Termios-script-diagram.svg ](https://commons.wikimedia.org/wiki/File:Termios-script-diagram.svg ) by [Krishnavedala ](https://en.wikipedia.org/wiki/User:Krishnavedala?rdfrom=commons:User:Krishnavedala ), used under [CC0 ](https://creativecommons.org/share-your-work/public-domain/cc0/ ).
## Properties
2024-03-29 07:07:43 +01:00
| Type | Name | Default |
| -------------- | ------------------------------------ | ------------------------------------------------------ |
| {{NodePath}} | [terminal_path ](#prop-terminal_path ) | None |
| {{int}} | [cols ](#prop-cols ) | 80 |
| {{int}} | [rows ](#prop-rows ) | 24 |
| {{Dictionary}} | [env ](#prop-env ) | `{ COLORTERM = "truecolor", TERM = "xterm-256color" }` |
| {{bool}} | [use_os_env ](#prop-use_os_env ) | true |
2022-08-07 12:49:29 +02:00
## Methods
2024-03-29 07:07:43 +01:00
| Returns | Signature |
| --------- | ------------------------------------------------------------------------------------------------------------------------------------------ |
| {{Error}} | [fork ](#mthd-fork ) ** (** {{String}} file=$SHELL, {{PoolStringArray}} args=[ ], {{String}} cwd=$PWD, {{int}} cols=80, {{int}} rows=24 ** )** |
| void | [kill ](#mthd-kill ) ** (** {{int}} signum=1 ** )** |
| {{Error}} | [open ](#mthd-open ) ** (** {{int}} cols=80, {{int}} rows=24 ** )** |
| void | [resize ](#mthd-resize ) ** (** {{int}} cols, {{int}} rows ** )** |
| void | [resizev ](#mthd-resizev ) ** (** {{Vector2}} size ** )** |
| void | [write ](#mthd-write ) ** (** {{String}}\|{{PoolByteArray}} data ** )** |
2022-08-07 12:49:29 +02:00
## Signals
2024-03-29 07:07:43 +01:00
< hr id = "sgnl-data_received" / >
**data_received** ** (** {{PoolByteArray}} data ** )**
2022-08-07 12:49:29 +02:00
2024-03-29 07:07:43 +01:00
Emitted when data is read from the pseudoterminal master device.
2022-08-07 12:49:29 +02:00
2024-03-29 07:07:43 +01:00
< hr id = "sgnl-exited" / >
2022-08-07 12:49:29 +02:00
2024-03-29 07:07:43 +01:00
**exited** ** (** {{int}} exit_code, {{int}} signum ** )**
2022-08-07 12:49:29 +02:00
2024-03-29 07:07:43 +01:00
Emitted when the child program exits. `exit_code` is the exit status of the child program and `signum` is the number of the signal that terminated the child program.
< hr / >
2022-08-07 12:49:29 +02:00
## Enumerations
2024-03-29 07:07:43 +01:00
< hr id = "enum-signal" / >
enum **Signal** :
2022-08-07 12:49:29 +02:00
- **SIGHUP** = 1 --- Hangup.
- **SIGINT** = 2 --- Terminal interrupt signal.
- **SIGQUIT** = 3 --- Terminal quit signal.
- **SIGILL** = 4 --- Illegal instruction.
- **SIGTRAP** = 5 --- Trace/breakpoint trap.
- **SIGABRT** = 6 --- Process abort signal.
- **SIGFPE** = 8 --- Erroneous arithmetic operation.
- **SIGKILL** = 9 --- Kill (cannot be caught or ignored).
- **SIGSEGV** = 11 --- Invalid memory reference.
- **SIGPIPE** = 13 --- Write on a pipe with no one to read it.
- **SIGALRM** = 14 --- Alarm clock.
- **SIGTERM** = 15 --- Termination signal.
2024-03-29 07:07:43 +01:00
< / hr >
2022-08-07 12:49:29 +02:00
## Property Descriptions
2024-03-29 07:07:43 +01:00
< hr id = "prop-terminal_path" / >
{{NodePath}} **terminal_path**
| | |
| --------- | --------------------------------------------- |
| _Default_ | None |
| _Setter_ | void set_terminal_path ( {{NodePath}} value ) |
| _Getter_ | None |
2022-08-07 12:49:29 +02:00
2024-03-29 07:07:43 +01:00
{{NodePath}} to a {{Terminal}}. Setting this path will automatically connect the appropriate signals of both nodes for standard operation. It will also disconnected the signals of the previously set terminal, if any.
2022-08-07 12:49:29 +02:00
2024-03-29 07:07:43 +01:00
< hr id = "prop-cols" / >
2022-08-07 12:49:29 +02:00
2024-03-29 07:07:43 +01:00
{{int}} **cols**
2022-08-07 12:49:29 +02:00
2024-03-29 07:07:43 +01:00
| | |
| --------- | ------------------------------- |
| _Default_ | 80 |
| _Setter_ | void set_cols ( {{int}} value ) |
| _Getter_ | None |
2022-08-07 12:49:29 +02:00
2024-03-29 07:07:43 +01:00
The column size in characters.
2022-08-07 12:49:29 +02:00
2024-03-29 07:07:43 +01:00
< hr id = "prop-rows" / >
2022-08-07 12:49:29 +02:00
2024-03-29 07:07:43 +01:00
{{int}} **rows**
2022-08-07 12:49:29 +02:00
2024-03-29 07:07:43 +01:00
| | |
| --------- | ------------------------------- |
| _Default_ | 24 |
| _Setter_ | void set_rows ( {{int}} value ) |
| _Getter_ | None |
2022-08-07 12:49:29 +02:00
2024-03-29 07:07:43 +01:00
The row size in characters.
2022-08-07 12:49:29 +02:00
2024-03-29 07:07:43 +01:00
< hr id = "prop-env" / >
2022-08-07 12:49:29 +02:00
2024-03-29 07:07:43 +01:00
{{Dictionary}} **env**
2022-08-07 12:49:29 +02:00
2024-03-29 07:07:43 +01:00
| | |
| --------- | ------------------------------------------------------ |
| _Default_ | `{ COLORTERM = "truecolor", TERM = "xterm-256color" }` |
| _Setter_ | None |
| _Getter_ | None |
2022-08-07 12:49:29 +02:00
2024-03-29 07:07:43 +01:00
Environment variables to be set for the child program.
2022-08-07 12:49:29 +02:00
2024-03-29 07:07:43 +01:00
< hr id = "prop-use_os_env" / >
2022-08-07 12:49:29 +02:00
2024-03-29 07:07:43 +01:00
{{bool}} **use_os_env**
2022-08-07 12:49:29 +02:00
2024-03-29 07:07:43 +01:00
| | |
| --------- | ---- |
| _Default_ | true |
| _Setter_ | None |
| _Getter_ | None |
2022-08-07 12:49:29 +02:00
2024-03-29 07:07:43 +01:00
If `true` the environment variables from `env` will be merged with the environment variables of the current program (i.e. Godot), with the variables from `env` taking precedence over the environment variables of the current program.
2022-08-07 12:49:29 +02:00
2024-03-29 07:07:43 +01:00
< / hr >
2022-08-07 12:49:29 +02:00
## Method Descriptions
2024-03-29 07:07:43 +01:00
< hr id = "mthd-fork" / >
2022-08-07 12:49:29 +02:00
2024-03-29 07:07:43 +01:00
{{Error}} **fork** ** (** {{String}} file=$SHELL, {{PoolStringArray}} args=[ ], {{String}} cwd=$PWD, {{int}} cols=80, {{int}} rows=24 ** )**
2022-08-07 12:49:29 +02:00
2024-03-29 07:07:43 +01:00
Opens a pseudoterminal and starts a new process using the program specified by `file` .
`file` defaults to the value of the `SHELL` environment variable, falling back to `sh` .
The arguments specified in `args` are passed to the program.
`cwd` is the directory in which the program will be executed. Defaults to the working directory of the current program (typically the project directory, when running from editor).
`cols` is the initial number of columns and `rows` is the initial number of rows.
Returns {{OK}} if successful.
2022-08-07 12:49:29 +02:00
2024-03-29 07:07:43 +01:00
:::{seealso}
Godot's {{ '[OS.execute()]({}/classes/class_os.html#class-os-method-execute)'.format(godot_docs) }} method.
:::
2022-08-07 12:49:29 +02:00
2024-03-29 07:07:43 +01:00
< hr id = "mthd-kill" / >
2022-08-07 12:49:29 +02:00
2024-03-29 07:07:43 +01:00
void **kill** ** (** {{int}} signum=1 ** )**
2022-08-07 12:49:29 +02:00
2024-03-29 07:07:43 +01:00
Sends the specified signal (`signum`) to the PTY's child process, if any. Defaults to `1` (`SIGHUP`).
2022-08-07 12:49:29 +02:00
2024-03-29 07:07:43 +01:00
:::{seealso}
Godot's {{ '[OS.kill()]({}/classes/class_os.html#class-os-method-kill)'.format(godot_docs) }} method.
:::
2022-08-07 12:49:29 +02:00
2024-03-29 07:07:43 +01:00
< hr id = "mthd-open" / >
2022-08-07 12:49:29 +02:00
2024-03-29 07:07:43 +01:00
{{Error}} **open** ** (** {{int}} cols=80, {{int}} rows=24 ** )**
2022-08-07 12:49:29 +02:00
2024-03-29 07:07:43 +01:00
Opens a pseudoterminal but does not start any process. Returns {{OK}} if successful.
2022-08-07 12:49:29 +02:00
2024-03-29 07:07:43 +01:00
< hr id = "mthd-resize" / >
2022-08-07 12:49:29 +02:00
2024-03-29 07:07:43 +01:00
void **resize** ** (** {{int}} cols, {{int}} rows ** )**
2022-08-07 12:49:29 +02:00
2024-03-29 07:07:43 +01:00
Resizes the dimensions of the pseudoterminal.
2022-08-07 12:49:29 +02:00
2024-03-29 07:07:43 +01:00
< hr id = "mthd-resizev" / >
2022-08-07 12:49:29 +02:00
2024-03-29 07:07:43 +01:00
void **resizev** ** (** {{Vector2}} size ** )**
2022-08-07 12:49:29 +02:00
2024-03-29 07:07:43 +01:00
Same as resize, but accepts a {{Vector2}} where `x` is cols and `y` is rows.
2022-08-07 12:49:29 +02:00
2024-03-29 07:07:43 +01:00
< hr id = "mthd-write" / >
2022-08-07 12:49:29 +02:00
2024-03-29 07:07:43 +01:00
void **write** ** (** {{String}}\|{{PoolByteArray}} data ** )**
2022-08-07 12:49:29 +02:00
2024-03-29 07:07:43 +01:00
Writes data to the pseudoterminal master device.