Skip to content

Instantly share code, notes, and snippets.

@KalleZ
Created August 10, 2016 19:04
Show Gist options
  • Save KalleZ/f3936c42a30649bfbed3219e419fc8a9 to your computer and use it in GitHub Desktop.
Save KalleZ/f3936c42a30649bfbed3219e419fc8a9 to your computer and use it in GitHub Desktop.
sapi/cli/php_cli.c | 31 +++++++++++++++++++++++++++++++
1 file changed, 31 insertions(+)
diff --git a/sapi/cli/php_cli.c b/sapi/cli/php_cli.c
index dc92045..2ea0c50 100644
--- a/sapi/cli/php_cli.c
+++ b/sapi/cli/php_cli.c
@@ -1226,6 +1226,37 @@ int main(int argc, char *argv[])
_CrtSetDbgFlag(tmp_flag);
}
#endif
+
+#if defined(PHP_WIN32)
+# ifndef ENABLE_VIRTUAL_TERMINAL_PROCESSING
+# define ENABLE_VIRTUAL_TERMINAL_PROCESSING 0x0004
+# endif
+ {
+ /*
+ * Set ENABLE_VIRTUAL_TERMINAL_PROCESSING on, for Windows 10+, however
+ * note that we can cross compile PHP on older platforms too, so this
+ * call will always be called regardless, as it would be slower to do
+ * a runtime check using GetVersionEx() just to ensure the platform
+ * for no reason
+ */
+ HANDLE php_stdout_handle = GetStdHandle(STD_OUTPUT_HANDLE);
+
+ /*
+ * Contrary to popular belief, these functions can actually fail, but we
+ * just ignore that, as it does not stop us from booting up PHP
+ */
+ if (php_stdout_handle != INVALID_HANDLE_VALUE) {
+ DWORD php_stdout_mode = 0;
+
+ if (GetConsoleMode(php_stdout_handle, (LPDWORD) php_stdout_mode) != 0) {
+ /* We already have enough ifs, ignore if SetConsoleMode() fails */
+ php_stdout_mode |= ENABLE_VIRTUAL_TERMINAL_PROCESSING;
+
+ SetConsoleMode(php_stdout_handle, php_stdout_mode);
+ }
+ }
+ }
+#endif
#ifdef HAVE_SIGNAL_H
#if defined(SIGPIPE) && defined(SIG_IGN)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment