From c7f04f1f9edd935eb7a3b81e6b91eaacb1fc928e Mon Sep 17 00:00:00 2001 From: Alexander Treml Date: Sun, 29 Jun 2025 15:39:20 +0200 Subject: [PATCH] added review suggestions --- addons/godot_xterm/native/SConstruct | 10 ++++++---- addons/godot_xterm/native/src/pty.cpp | 18 +++++++++++++----- addons/godot_xterm/plugin.gd | 2 +- 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/addons/godot_xterm/native/SConstruct b/addons/godot_xterm/native/SConstruct index c635fca..fc5659d 100644 --- a/addons/godot_xterm/native/SConstruct +++ b/addons/godot_xterm/native/SConstruct @@ -27,16 +27,18 @@ sources.append([ if env['platform'] == 'linux' or env['platform'] == 'macos': env.Append(LIBS=['util', env.File('thirdparty/libuv/build/libuv_a.a')]) -else: +elif env['platform'] == 'windows': env.Append(LIBS=['ws2_32.lib', 'Advapi32', 'User32', 'Userenv', 'iphlpapi']) if env["target"] == "template_release": env.Append(LIBS=[env.File('thirdparty/libuv/build/Release/uv_a.lib')]) else: env.Append(LIBS=[env.File('thirdparty/libuv/build/Debug/uv_a.lib')]) + # TODO(ast) this is a bandaid fix (see https://stackoverflow.com/questions/3007312/resolving-lnk4098-defaultlib-msvcrt-conflicts-with) + # TODO(ast) a release build needs to use msvcrt instead of msvcrtd + env.Append(LINKFLAGS=['/VERBOSE:LIB', '/NODEFAULTLIB:libcmtd.lib', '/NODEFAULTLIB:libcmt.lib', '/NODEFAULTLIB:msvcrt.lib']) +else: + env.Append(CPPDEFINES=['_PTY_DISABLED']) -# TODO(ast) this is a bandaid fix (see https://stackoverflow.com/questions/3007312/resolving-lnk4098-defaultlib-msvcrt-conflicts-with) -# TODO(ast) a release build needs to use msvcrt instead of msvcrtd -env.Append(LINKFLAGS=['/VERBOSE:LIB', '/NODEFAULTLIB:libcmtd.lib', '/NODEFAULTLIB:libcmt.lib', '/NODEFAULTLIB:msvcrt.lib']) if env["platform"] == "macos": library = env.SharedLibrary( diff --git a/addons/godot_xterm/native/src/pty.cpp b/addons/godot_xterm/native/src/pty.cpp index 0493d0e..228a776 100644 --- a/addons/godot_xterm/native/src/pty.cpp +++ b/addons/godot_xterm/native/src/pty.cpp @@ -321,12 +321,20 @@ void PTY::write(const Variant &data) const if (status == STATUS_OPEN) { + #if defined(__linux__) || defined(__APPLE__) || defined(_WIN32) uv_buf_t buf; buf.base = (char *)bytes.ptr(); buf.len = bytes.size(); uv_write_t *req = (uv_write_t *)malloc(sizeof(uv_write_t)); req->data = (void *)buf.base; + #endif + + #if defined(__linux__) || defined(__APPLE__) + uv_write(req, (uv_stream_t *)&pipe, &buf, 1, _write_cb); + #elif defined(_WIN32) uv_write(req, (uv_stream_t *)&pipe_out, &buf, 1, _write_cb); + #endif + uv_run((uv_loop_t *)&loop, UV_RUN_NOWAIT); } } @@ -400,15 +408,15 @@ void PTY::_close() uv_loop_close(&loop); } -#ifdef _WIN32 - PTYWin::close(hpc, fd, fd_out); - fd_out = -1; - hpc = -1; -#else +#if defined(__linux__) || defined(__APPLE__) if (fd > 0) close(fd); if (pid > 0) kill(IPCSIGNAL_SIGHUP); +#elif defined(_WIN32) + PTYWin::close(hpc, fd, fd_out); + fd_out = -1; + hpc = -1; #endif fd = -1; diff --git a/addons/godot_xterm/plugin.gd b/addons/godot_xterm/plugin.gd index ff1f78e..4725f29 100644 --- a/addons/godot_xterm/plugin.gd +++ b/addons/godot_xterm/plugin.gd @@ -1,7 +1,7 @@ @tool extends EditorPlugin -var pty_supported := OS.get_name() in ["Linux", "FreeBSD", "NetBSD", "OpenBSD", "BSD", "macOS"] +var pty_supported := OS.get_name() in ["Linux", "FreeBSD", "NetBSD", "OpenBSD", "BSD", "macOS", "Windows"] var asciicast_import_plugin var xrdb_import_plugin var terminal_panel: Control