From 39b5614f61273730e67ea0c85d4b466134d55c85 Mon Sep 17 00:00:00 2001 From: Leroy Hopson Date: Fri, 1 Mar 2024 20:25:51 +1300 Subject: [PATCH] feat(pty): use process internal, not _process --- addons/godot_xterm/native/src/pty.cpp | 21 +++++++++++++++++---- addons/godot_xterm/native/src/pty.h | 3 ++- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/addons/godot_xterm/native/src/pty.cpp b/addons/godot_xterm/native/src/pty.cpp index 6b0913f..a8c37c9 100644 --- a/addons/godot_xterm/native/src/pty.cpp +++ b/addons/godot_xterm/native/src/pty.cpp @@ -131,6 +131,9 @@ Error PTY::fork(const String &file, const PackedStringArray &args, const String } #endif + status = STATUS_CONNECTED; + set_process_internal(true); + return OK; } @@ -191,19 +194,31 @@ void PTY::write(const Variant &data) const { } } -void PTY::_process(double delta) { +void PTY::_notification(int p_what) { + switch (p_what) + { + case NOTIFICATION_INTERNAL_PROCESS: + _run(UV_RUN_NOWAIT); + break; + } +} + +void PTY::_run(uv_run_mode mode) { #if defined(__linux__) || defined(__APPLE__) if (status == STATUS_CONNECTED) { if (!uv_is_active((uv_handle_t *)&pipe)) { uv_read_start((uv_stream_t *)&pipe, _alloc_buffer, _read_cb); } - uv_run(uv_default_loop(), UV_RUN_NOWAIT); + uv_run(uv_default_loop(), mode); } #endif } void PTY::_close() { + set_process_internal(false); + status = STATUS_NONE; + #if defined(__linux__) || defined(__APPLE__) if (!uv_is_closing((uv_handle_t *)&pipe)) { uv_close((uv_handle_t *)&pipe, _close_cb); @@ -216,7 +231,6 @@ void PTY::_close() { fd = -1; pid = -1; - status = STATUS_NONE; #endif } @@ -350,7 +364,6 @@ Error PTY::_pipe_open(const int fd) { ERR_FAIL_UV_ERR(uv_stream_set_blocking((uv_stream_t *)&pipe, false)); ERR_FAIL_UV_ERR(uv_read_start((uv_stream_t *)&pipe, _alloc_buffer, _read_cb)); - status = STATUS_CONNECTED; return OK; } diff --git a/addons/godot_xterm/native/src/pty.h b/addons/godot_xterm/native/src/pty.h index a3744ee..fc73a00 100644 --- a/addons/godot_xterm/native/src/pty.h +++ b/addons/godot_xterm/native/src/pty.h @@ -63,7 +63,8 @@ namespace godot void resizev(const Vector2i &size) const { resize(size.x, size.y); }; void write(const Variant &data) const; - void _process(double delta) override; + void _notification(int p_what); + void _run(uv_run_mode mode); protected: static void _bind_methods();