summaryrefslogtreecommitdiffstats
path: root/modules
diff options
context:
space:
mode:
Diffstat (limited to 'modules')
-rw-r--r--modules/text_server_adv/gdextension_build/SConstruct23
-rw-r--r--modules/text_server_fb/gdextension_build/SConstruct23
2 files changed, 30 insertions, 16 deletions
diff --git a/modules/text_server_adv/gdextension_build/SConstruct b/modules/text_server_adv/gdextension_build/SConstruct
index 018984a52f..58e1868e31 100644
--- a/modules/text_server_adv/gdextension_build/SConstruct
+++ b/modules/text_server_adv/gdextension_build/SConstruct
@@ -6,14 +6,21 @@ import time
# Enable ANSI escape code support on Windows 10 and later (for colored console output).
# <https://github.com/python/cpython/issues/73245>
-if sys.platform == "win32":
- from ctypes import windll, c_int, byref
-
- stdout_handle = windll.kernel32.GetStdHandle(c_int(-11))
- mode = c_int(0)
- windll.kernel32.GetConsoleMode(c_int(stdout_handle), byref(mode))
- mode = c_int(mode.value | 4)
- windll.kernel32.SetConsoleMode(c_int(stdout_handle), mode)
+if sys.stdout.isatty() and sys.platform == "win32":
+ try:
+ from ctypes import windll, byref, WinError # type: ignore
+ from ctypes.wintypes import DWORD # type: ignore
+
+ stdout_handle = windll.kernel32.GetStdHandle(DWORD(-11))
+ mode = DWORD(0)
+ if not windll.kernel32.GetConsoleMode(stdout_handle, byref(mode)):
+ raise WinError()
+ mode = DWORD(mode.value | 4)
+ if not windll.kernel32.SetConsoleMode(stdout_handle, mode):
+ raise WinError()
+ except Exception as e:
+ methods._colorize = False
+ methods.print_error(f"Failed to enable ANSI escape code support, disabling color output.\n{e}")
# For the reference:
# - CCFLAGS are compilation flags shared between C and C++
diff --git a/modules/text_server_fb/gdextension_build/SConstruct b/modules/text_server_fb/gdextension_build/SConstruct
index 07940719eb..9326a53026 100644
--- a/modules/text_server_fb/gdextension_build/SConstruct
+++ b/modules/text_server_fb/gdextension_build/SConstruct
@@ -6,14 +6,21 @@ import time
# Enable ANSI escape code support on Windows 10 and later (for colored console output).
# <https://github.com/python/cpython/issues/73245>
-if sys.platform == "win32":
- from ctypes import windll, c_int, byref
-
- stdout_handle = windll.kernel32.GetStdHandle(c_int(-11))
- mode = c_int(0)
- windll.kernel32.GetConsoleMode(c_int(stdout_handle), byref(mode))
- mode = c_int(mode.value | 4)
- windll.kernel32.SetConsoleMode(c_int(stdout_handle), mode)
+if sys.stdout.isatty() and sys.platform == "win32":
+ try:
+ from ctypes import windll, byref, WinError # type: ignore
+ from ctypes.wintypes import DWORD # type: ignore
+
+ stdout_handle = windll.kernel32.GetStdHandle(DWORD(-11))
+ mode = DWORD(0)
+ if not windll.kernel32.GetConsoleMode(stdout_handle, byref(mode)):
+ raise WinError()
+ mode = DWORD(mode.value | 4)
+ if not windll.kernel32.SetConsoleMode(stdout_handle, mode):
+ raise WinError()
+ except Exception as e:
+ methods._colorize = False
+ methods.print_error(f"Failed to enable ANSI escape code support, disabling color output.\n{e}")
# For the reference:
# - CCFLAGS are compilation flags shared between C and C++