mirror of
https://github.com/lihop/godot-xterm.git
synced 2024-11-21 17:20:25 +01:00
chore: remove unused code
This commit is contained in:
parent
7efd7218b0
commit
98394bfbf5
13 changed files with 8 additions and 478 deletions
|
@ -2,7 +2,7 @@
|
|||
|
||||
[ext_resource type="Script" path="res://addons/godot_xterm/editor_plugins/terminal/terminal_panel.gd" id="1"]
|
||||
|
||||
[sub_resource type="Image" id="Image_cfx3h"]
|
||||
[sub_resource type="Image" id="Image_dp2w7"]
|
||||
data = {
|
||||
"data": PackedByteArray(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 224, 224, 224, 0, 224, 224, 224, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 224, 224, 224, 0, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 224, 224, 224, 0, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 224, 224, 224, 0, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 224, 224, 224, 0, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 224, 224, 224, 0, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 224, 224, 224, 0, 224, 224, 224, 0, 224, 224, 224, 0, 224, 224, 224, 0, 224, 224, 224, 0, 224, 224, 224, 0, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 0, 224, 224, 224, 0, 224, 224, 224, 0, 224, 224, 224, 0, 224, 224, 224, 0, 224, 224, 224, 0, 0, 0, 0, 0, 224, 224, 224, 0, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 0, 224, 224, 224, 0, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 0, 0, 0, 0, 0, 224, 224, 224, 0, 224, 224, 224, 0, 224, 224, 224, 0, 224, 224, 224, 0, 224, 224, 224, 0, 224, 224, 224, 0, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 0, 224, 224, 224, 0, 224, 224, 224, 0, 224, 224, 224, 0, 224, 224, 224, 0, 224, 224, 224, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 224, 224, 224, 0, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 224, 224, 224, 0, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 224, 224, 224, 0, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 224, 224, 224, 0, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 224, 224, 224, 0, 224, 224, 224, 255, 224, 224, 224, 255, 224, 224, 224, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 224, 224, 224, 0, 224, 224, 224, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
|
||||
"format": "RGBA8",
|
||||
|
@ -12,7 +12,7 @@ data = {
|
|||
}
|
||||
|
||||
[sub_resource type="ImageTexture" id="ImageTexture_q1uu0"]
|
||||
image = SubResource("Image_cfx3h")
|
||||
image = SubResource("Image_dp2w7")
|
||||
|
||||
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_osmrc"]
|
||||
bg_color = Color(0.113329, 0.129458, 0.156802, 1)
|
||||
|
|
Before Width: | Height: | Size: 1.3 KiB After Width: | Height: | Size: 1.3 KiB |
|
@ -3,15 +3,15 @@
|
|||
importer="texture"
|
||||
type="CompressedTexture2D"
|
||||
uid="uid://q1dpdt7xx8jf"
|
||||
path="res://.godot/imported/pty_icon.svg-e9e42570b4744b3370a02d174395c793.ctex"
|
||||
path="res://.godot/imported/pty_icon.svg-7c3f500292e2f95935d23c435d6de47f.ctex"
|
||||
metadata={
|
||||
"vram_texture": false
|
||||
}
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://addons/godot_xterm/nodes/pty/pty_icon.svg"
|
||||
dest_files=["res://.godot/imported/pty_icon.svg-e9e42570b4744b3370a02d174395c793.ctex"]
|
||||
source_file="res://addons/godot_xterm/icons/pty_icon.svg"
|
||||
dest_files=["res://.godot/imported/pty_icon.svg-7c3f500292e2f95935d23c435d6de47f.ctex"]
|
||||
|
||||
[params]
|
||||
|
Before Width: | Height: | Size: 1.3 KiB After Width: | Height: | Size: 1.3 KiB |
|
@ -3,15 +3,15 @@
|
|||
importer="texture"
|
||||
type="CompressedTexture2D"
|
||||
uid="uid://b1cq080dxs1ft"
|
||||
path="res://.godot/imported/terminal_icon.svg-a0706fd47bb880823b1242c224120d4f.ctex"
|
||||
path="res://.godot/imported/terminal_icon.svg-2a4b198a0e3aa43f04b43cec3e3f109d.ctex"
|
||||
metadata={
|
||||
"vram_texture": false
|
||||
}
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://addons/godot_xterm/nodes/terminal/terminal_icon.svg"
|
||||
dest_files=["res://.godot/imported/terminal_icon.svg-a0706fd47bb880823b1242c224120d4f.ctex"]
|
||||
source_file="res://addons/godot_xterm/icons/terminal_icon.svg"
|
||||
dest_files=["res://.godot/imported/terminal_icon.svg-2a4b198a0e3aa43f04b43cec3e3f109d.ctex"]
|
||||
|
||||
[params]
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
[gd_resource type="NativeScript" load_steps=2 format=2]
|
||||
|
||||
[ext_resource path="res://addons/godot_xterm/native/godotxtermnative.gdnlib" type="GDNativeLibrary" id=1]
|
||||
|
||||
[resource]
|
||||
resource_name = "Terminal"
|
||||
class_name = "LibuvUtils"
|
||||
library = ExtResource( 1 )
|
|
@ -1,8 +0,0 @@
|
|||
[gd_resource type="NativeScript" load_steps=2 format=2]
|
||||
|
||||
[ext_resource path="res://addons/godot_xterm/native/godotxtermnative.gdnlib" type="GDNativeLibrary" id=1]
|
||||
|
||||
[resource]
|
||||
resource_name = "Terminal"
|
||||
class_name = "Pipe"
|
||||
library = ExtResource( 1 )
|
|
@ -1,24 +0,0 @@
|
|||
@tool
|
||||
extends Node
|
||||
|
||||
signal data_received(data)
|
||||
signal exited(exit_code, signum)
|
||||
|
||||
|
||||
func open(cols: int, rows: int):
|
||||
return _not_implemented()
|
||||
|
||||
|
||||
func resize(cols: int, rows: int):
|
||||
return _not_implemented()
|
||||
|
||||
|
||||
func _not_implemented() -> int:
|
||||
var method := ""
|
||||
|
||||
var stack = get_stack()
|
||||
if stack.size() >= 2 and "function" in stack[1]:
|
||||
method = "%s()" % stack[1].function
|
||||
|
||||
push_error("Method %s not implemented on the current platform (%s)." % [method, OS.get_name()])
|
||||
return ERR_METHOD_NOT_FOUND
|
|
@ -1,221 +0,0 @@
|
|||
# Derived from https://github.com/microsoft/node-pty/blob/main/src/unixTerminal.ts
|
||||
# Copyright (c) 2012-2015, Christopher Jeffrey (MIT License).
|
||||
# Copyright (c) 2016, Daniel Imms (MIT License).
|
||||
# Copyright (c) 2018, Microsoft Corporation (MIT License).
|
||||
# Copyright (c) 2021-2022, Leroy Hopson (MIT License).
|
||||
@tool
|
||||
extends "../pty_native.gd"
|
||||
|
||||
const DEFAULT_NAME := "xterm-256color"
|
||||
const DEFAULT_COLS := 80
|
||||
const DEFAULT_ROWS := 24
|
||||
const DEFAULT_ENV := {TERM = DEFAULT_NAME, COLORTERM = "truecolor"}
|
||||
|
||||
const FALLBACK_FILE = "sh"
|
||||
|
||||
## Default messages to indicate PAUSE/RESUME for automatic flow control.
|
||||
## To avoid conflicts with rebound XON/XOFF control codes (such as on-my-zsh),
|
||||
## the sequences can be customized in IPtyForkOptions.
|
||||
#const FLOW_CONTROL_PAUSE = char(0x13) # defaults to XOFF
|
||||
#const FLOW_CONTROL_RESUME = char(0x11) # defaults to XON
|
||||
|
||||
# Any signal_number can be sent to the pty's process using the kill() function,
|
||||
# these are just the signals with numbers specified in the POSIX standard.
|
||||
enum IPCSignal {
|
||||
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
|
||||
}
|
||||
|
||||
var _LibuvUtils = (
|
||||
ClassDB.instantiate("LibuvUtils").get_class() if ClassDB.class_exists("LibuvUtils") else null
|
||||
)
|
||||
var _Pipe = ClassDB.instantiate("Pipe").get_class() if ClassDB.class_exists("Pipe") else null
|
||||
var _PTYUnix = (
|
||||
ClassDB.instantiate("PTYUnix").get_class() if ClassDB.class_exists("PTYUnix") else null
|
||||
)
|
||||
|
||||
# The name of the process.
|
||||
#var process: String
|
||||
|
||||
# The process ID.
|
||||
var _pid: int
|
||||
|
||||
# Environment to be set for the child program.
|
||||
var env := DEFAULT_ENV
|
||||
|
||||
# If true the environment variables in the env Dictionary will be merged with
|
||||
# the environment variables of the operating system (e.g. printenv), with the
|
||||
# former taking precedence in the case of conflicts.
|
||||
var use_os_env := true
|
||||
|
||||
var _pipe = _Pipe
|
||||
|
||||
# Security warning: use this option with great caution, as opened file descriptors
|
||||
# with higher privileges might leak to the child program.
|
||||
var uid: int
|
||||
var gid: int
|
||||
|
||||
var _fd: int = -1
|
||||
var _exit_cb: Callable
|
||||
|
||||
|
||||
# Writes data to the socket.
|
||||
# data: The data to write.
|
||||
func write(data) -> void:
|
||||
var correct_type: bool = data is PackedByteArray or data is String
|
||||
var err_message := "Invalid type for argument 'data'. Should be of type PackedByteArray or String"
|
||||
assert(correct_type, err_message)
|
||||
|
||||
if _pipe:
|
||||
_pipe.write(data if data is PackedByteArray else data.to_utf8_buffer())
|
||||
|
||||
|
||||
func resize(cols: int, rows: int) -> void:
|
||||
if _fd >= 0:
|
||||
_PTYUnix.new().resize(_fd, cols, rows)
|
||||
|
||||
|
||||
func kill(signum: int = IPCSignal.SIGHUP) -> void:
|
||||
if _pipe:
|
||||
_pipe.close()
|
||||
if _pid > 0:
|
||||
_LibuvUtils.kill(_pid, signum)
|
||||
|
||||
|
||||
func _parse_env(env: Dictionary = {}) -> PackedStringArray:
|
||||
var keys := env.keys()
|
||||
var pairs := PackedStringArray()
|
||||
|
||||
for key in keys:
|
||||
var value = env[key]
|
||||
var valid = key is String and value is String
|
||||
assert(valid) #,"Env key/value pairs must be of type String/String.")
|
||||
|
||||
if not valid:
|
||||
push_warning("Skipping invalid env key/value pair.")
|
||||
continue
|
||||
|
||||
pairs.append("%s=%s" % [key, value])
|
||||
|
||||
return pairs
|
||||
|
||||
|
||||
func _process(_delta):
|
||||
if _pipe:
|
||||
_pipe.poll()
|
||||
|
||||
|
||||
func fork(
|
||||
file: String = OS.get_environment("SHELL"),
|
||||
args: PackedStringArray = PackedStringArray(),
|
||||
cwd = _LibuvUtils.get_cwd(),
|
||||
cols: int = DEFAULT_COLS,
|
||||
rows: int = DEFAULT_ROWS,
|
||||
uid: int = -1,
|
||||
gid: int = -1,
|
||||
utf8 = true
|
||||
) -> int:
|
||||
# File.
|
||||
if file.is_empty():
|
||||
file = FALLBACK_FILE
|
||||
|
||||
# Environment variables.
|
||||
# If we are using OS env vars, sanitize them to remove variables that might confuse our terminal.
|
||||
var final_env := _sanitize_env(_LibuvUtils.get_os_environ()) if use_os_env else {}
|
||||
for key in env.keys():
|
||||
final_env[key] = env[key]
|
||||
var parsed_env: PackedStringArray = _parse_env(final_env)
|
||||
|
||||
# Exit callback.
|
||||
_exit_cb = Callable(self, "on_exit")
|
||||
|
||||
# Actual fork.
|
||||
var result = (
|
||||
_PTYUnix
|
||||
. new()
|
||||
. fork(
|
||||
# VERY IMPORTANT: The second argument must be 0, otherwise will get an ENOTSOCK error after connecting our pipe to the fd.
|
||||
file,
|
||||
0,
|
||||
args,
|
||||
parsed_env,
|
||||
cwd,
|
||||
cols,
|
||||
rows,
|
||||
uid,
|
||||
gid,
|
||||
utf8,
|
||||
_exit_cb
|
||||
)
|
||||
)
|
||||
|
||||
if result[0] != OK:
|
||||
push_error("Fork failed.")
|
||||
return FAILED
|
||||
|
||||
_fd = result[1].fd
|
||||
if _fd < 0:
|
||||
push_error("File descriptor must be a non-negative integer value.")
|
||||
return FAILED
|
||||
|
||||
_pid = result[1].pid
|
||||
|
||||
_pipe = _Pipe.new()
|
||||
_pipe.open(_fd, false)
|
||||
|
||||
# Must connect to signal AFTER opening, otherwise we will get error ENOTSOCK.
|
||||
_pipe.connect("data_received", Callable(self, "_on_pipe_data_received"))
|
||||
|
||||
return OK
|
||||
|
||||
|
||||
func open(cols: int = DEFAULT_COLS, rows: int = DEFAULT_ROWS) -> Array:
|
||||
return _PTYUnix.new().open(cols, rows)
|
||||
|
||||
|
||||
func _exit_tree():
|
||||
_exit_cb = Callable()
|
||||
if _pid > 1:
|
||||
_LibuvUtils.kill(_pid, IPCSignal.SIGHUP)
|
||||
if _pipe:
|
||||
while _pipe.get_status() != 0:
|
||||
continue
|
||||
|
||||
|
||||
func _on_pipe_data_received(data):
|
||||
emit_signal("data_received", data)
|
||||
|
||||
|
||||
func _on_exit(exit_code: int, signum: int) -> void:
|
||||
if is_instance_valid(self):
|
||||
_pid = -1
|
||||
emit_signal("exited", exit_code, signum)
|
||||
|
||||
|
||||
func _sanitize_env(env: Dictionary) -> Dictionary:
|
||||
# Make sure we didn't start our server from inside tmux.
|
||||
env.erase("TMUX")
|
||||
env.erase("TMUX_PANE")
|
||||
|
||||
# Make sure we didn't start our server from inside screen.
|
||||
# http://web.mit.edu/gnu/doc/html/screen_20.html
|
||||
env.erase("STY")
|
||||
env.erase("WINDOW")
|
||||
|
||||
# Delete some variables that might confuse our terminal.
|
||||
env.erase("WINDOWID")
|
||||
env.erase("TERMCAP")
|
||||
env.erase("COLUMNS")
|
||||
env.erase("LINES")
|
||||
|
||||
return env
|
|
@ -1,7 +0,0 @@
|
|||
[gd_resource type="NativeScript" load_steps=2 format=2]
|
||||
|
||||
[ext_resource path="res://addons/godot_xterm/native/godotxtermnative.gdnlib" type="GDNativeLibrary" id=1]
|
||||
|
||||
[resource]
|
||||
class_name = "PTYUnix"
|
||||
library = ExtResource( 1 )
|
|
@ -1,8 +0,0 @@
|
|||
[gd_resource type="NativeScript" load_steps=2 format=2]
|
||||
|
||||
[ext_resource path="res://addons/godot_xterm/native/godotxtermnative.gdnlib" type="GDNativeLibrary" id=1]
|
||||
|
||||
[resource]
|
||||
resource_name = "Terminal"
|
||||
class_name = "Terminal"
|
||||
library = ExtResource( 1 )
|
|
@ -1,194 +0,0 @@
|
|||
# Derived from https://github.com/microsoft/node-pty/blob/main/src/terminal.ts
|
||||
# Copyright (c) 2012-2015, Christopher Jeffrey (MIT License).
|
||||
# Copyright (c) 2016, Daniel Imms (MIT License).
|
||||
# Copyright (c) 2018, Microsoft Corporation (MIT License).
|
||||
# Copyright (c) 2021-2022, Leroy Hopson (MIT License).
|
||||
@tool
|
||||
extends Node
|
||||
|
||||
var _LibuvUtils = (
|
||||
ClassDB.instantiate("LibuvUtils").get_class() if ClassDB.class_exists("LibuvUtils") else null
|
||||
)
|
||||
|
||||
const _PTYNative := preload("./nodes/pty/pty_native.gd")
|
||||
const _PTYUnix := preload("./nodes/pty/unix/pty_unix.gd")
|
||||
|
||||
const DEFAULT_NAME := "xterm-256color"
|
||||
const DEFAULT_COLS := 80
|
||||
const DEFAULT_ROWS := 24
|
||||
const DEFAULT_ENV := {TERM = DEFAULT_NAME, COLORTERM = "truecolor"}
|
||||
|
||||
# Any signal_number can be sent to the pty's process using the kill() function,
|
||||
# these are just the signals with numbers specified in the POSIX standard.
|
||||
const IPCSignal = _PTYUnix.IPCSignal
|
||||
|
||||
signal data_received(data)
|
||||
signal exited(exit_code, signum)
|
||||
|
||||
@export var terminal_path: NodePath = NodePath():
|
||||
get:
|
||||
return terminal_path
|
||||
set(value):
|
||||
terminal_path = value
|
||||
_set_terminal(get_node_or_null(terminal_path))
|
||||
|
||||
var _terminal
|
||||
|
||||
# The column size in characters.
|
||||
@export var cols: int = DEFAULT_COLS:
|
||||
get:
|
||||
return cols # TODOConverter40 Copy here content of get_cols
|
||||
set(mod_value):
|
||||
mod_value # TODOConverter40 Copy here content of set_cols
|
||||
|
||||
# The row size in characters.
|
||||
@export var rows: int = DEFAULT_ROWS:
|
||||
get:
|
||||
return rows # TODOConverter40 Copy here content of get_rows
|
||||
set(mod_value):
|
||||
mod_value # TODOConverter40 Copy here content of set_rows
|
||||
|
||||
# Environment to be set for the child program.
|
||||
@export var env: Dictionary = DEFAULT_ENV
|
||||
|
||||
# If true the environment variables in the env Dictionary will be merged with
|
||||
# the environment variables of the operating system (e.g. printenv), with the
|
||||
# former taking precedence in the case of conflicts.
|
||||
@export var use_os_env: bool = true
|
||||
|
||||
var _cols := DEFAULT_COLS
|
||||
var _rows := DEFAULT_ROWS
|
||||
var _pty_native: _PTYNative
|
||||
|
||||
|
||||
func _init():
|
||||
var os_name := OS.get_name()
|
||||
match os_name:
|
||||
"Linux", "FreeBSD", "NetBSD", "OpenBSD", "BSD", "macOS":
|
||||
_pty_native = _PTYUnix.new()
|
||||
_:
|
||||
push_error("PTY is not supported on the current platform (%s)." % os_name)
|
||||
|
||||
_pty_native.connect("data_received", Callable(self, "_on_pty_native_data_received"))
|
||||
_pty_native.connect("exited", Callable(self, "_on_pty_native_exited"))
|
||||
|
||||
add_child(_pty_native)
|
||||
|
||||
|
||||
func _ready():
|
||||
if not (terminal_path.is_empty()) and not _terminal:
|
||||
self.terminal_path = terminal_path
|
||||
|
||||
|
||||
func set_cols(value: int):
|
||||
resize(value, _rows)
|
||||
|
||||
|
||||
func get_cols() -> int:
|
||||
return _cols
|
||||
|
||||
|
||||
func set_rows(value: int):
|
||||
resize(_cols, value)
|
||||
|
||||
|
||||
func get_rows() -> int:
|
||||
return _rows
|
||||
|
||||
|
||||
func _set_terminal(value):
|
||||
if _terminal == value:
|
||||
return
|
||||
|
||||
# Disconnect the current terminal, if any.
|
||||
if _terminal != null:
|
||||
disconnect("data_received", Callable(_terminal, "write"))
|
||||
_terminal.disconnect("data_sent", Callable(self, "write"))
|
||||
_terminal.disconnect("size_changed", Callable(self, "resizev"))
|
||||
|
||||
_terminal = value
|
||||
|
||||
if _terminal == null:
|
||||
return
|
||||
|
||||
# Connect the new terminal.
|
||||
resize(_terminal.get_cols(), _terminal.get_rows())
|
||||
if not _terminal.is_connected("size_changed", Callable(self, "resizev")):
|
||||
_terminal.connect("size_changed", Callable(self, "resizev"))
|
||||
if not _terminal.is_connected("data_sent", Callable(self, "write")):
|
||||
_terminal.connect("data_sent", Callable(self, "write"))
|
||||
if not is_connected("data_received", Callable(_terminal, "write")):
|
||||
connect("data_received", Callable(_terminal, "write"))
|
||||
|
||||
|
||||
# Writes data to the socket.
|
||||
# data: The data to write.
|
||||
func write(data) -> void:
|
||||
_pty_native.write(data)
|
||||
|
||||
|
||||
# Resizes the dimensions of the pty.
|
||||
# cols: The number of columns.
|
||||
# rows: The number of rows.
|
||||
func resize(cols = _cols, rows = _rows) -> void:
|
||||
if not _valid_size(cols, rows):
|
||||
push_error("Size of cols/rows must be a positive integer.")
|
||||
return
|
||||
|
||||
_cols = cols
|
||||
_rows = rows
|
||||
|
||||
_pty_native.resize(_cols, _rows)
|
||||
|
||||
|
||||
# Same as resize() but takes a Vector2.
|
||||
func resizev(size: Vector2) -> void:
|
||||
resize(int(size.x), int(size.y))
|
||||
|
||||
|
||||
# Kill the pty.
|
||||
# sigint: The signal to send. By default this is SIGHUP.
|
||||
# This is not supported on Windows.
|
||||
func kill(signum: int = IPCSignal.SIGHUP) -> void:
|
||||
_pty_native.kill(signum)
|
||||
|
||||
|
||||
func _notification(what: int):
|
||||
match what:
|
||||
NOTIFICATION_PARENTED:
|
||||
var parent = get_parent()
|
||||
if parent is Terminal:
|
||||
self.terminal_path = get_path_to(parent)
|
||||
|
||||
|
||||
func fork(
|
||||
file: String = OS.get_environment("SHELL"),
|
||||
args: PackedStringArray = PackedStringArray(),
|
||||
cwd = _LibuvUtils.get_cwd(),
|
||||
cols: int = _cols,
|
||||
rows: int = _rows,
|
||||
uid: int = -1,
|
||||
gid: int = -1,
|
||||
utf8 = true
|
||||
) -> int:
|
||||
resize(cols, rows) # Ensures error message is printed if cols/rows are invalid.
|
||||
if not _valid_size(cols, rows):
|
||||
return ERR_INVALID_PARAMETER
|
||||
|
||||
return _pty_native.fork(file, args, cwd, _cols, _rows, uid, gid, utf8)
|
||||
|
||||
|
||||
func open(cols: int = DEFAULT_COLS, rows: int = DEFAULT_ROWS) -> Array:
|
||||
return _pty_native.open(cols, rows)
|
||||
|
||||
|
||||
func _on_pty_native_data_received(data):
|
||||
emit_signal("data_received", data)
|
||||
|
||||
|
||||
func _on_pty_native_exited(exit_code: int, signum: int) -> void:
|
||||
emit_signal("exited", exit_code, signum)
|
||||
|
||||
|
||||
static func _valid_size(cols: int, rows: int) -> bool:
|
||||
return cols > 0 and rows > 0 and cols != NAN and rows != NAN and cols != INF and rows != INF
|
Loading…
Reference in a new issue