summaryrefslogtreecommitdiff
path: root/sapi/cli/php_cli_server.c
diff options
context:
space:
mode:
authorChristoph M. Becker <cmbecker69@gmx.de>2020-08-16 17:24:13 +0200
committerChristoph M. Becker <cmbecker69@gmx.de>2020-08-28 18:45:09 +0200
commit1902f730ee2bda60552f34c0643e2d7b47e4fb64 (patch)
tree8a8dae5986590a736b21e5913c1aa263b501f9f6 /sapi/cli/php_cli_server.c
parenta1a4c03b9b5fc201abb0bbe320bf72f1eb230250 (diff)
downloadphp-git-1902f730ee2bda60552f34c0643e2d7b47e4fb64.tar.gz
Support cli_server.color on Windows
On Windows, we have to check whether stdout is attached to a console, and whether that console supports VT100 control codes. Closes GH-5996
Diffstat (limited to 'sapi/cli/php_cli_server.c')
-rw-r--r--sapi/cli/php_cli_server.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/sapi/cli/php_cli_server.c b/sapi/cli/php_cli_server.c
index dd721ccac5..64e29e8524 100644
--- a/sapi/cli/php_cli_server.c
+++ b/sapi/cli/php_cli_server.c
@@ -215,7 +215,7 @@ static php_cli_server_http_response_status_code_pair template_map[] = {
static int php_cli_server_log_level = 3;
-#if HAVE_UNISTD_H
+#if HAVE_UNISTD_H || defined(PHP_WIN32)
static int php_cli_output_is_tty = OUTPUT_NOT_CHECKED;
#endif
@@ -1160,6 +1160,14 @@ static int php_cli_is_output_tty() /* {{{ */
}
return php_cli_output_is_tty;
} /* }}} */
+#elif defined(PHP_WIN32)
+static int php_cli_is_output_tty() /* {{{ */
+{
+ if (php_cli_output_is_tty == OUTPUT_NOT_CHECKED) {
+ php_cli_output_is_tty = php_win32_console_fileno_is_console(STDOUT_FILENO) && php_win32_console_fileno_has_vt100(STDOUT_FILENO);
+ }
+ return php_cli_output_is_tty;
+} /* }}} */
#endif
static void php_cli_server_log_response(php_cli_server_client *client, int status, const char *message) /* {{{ */
@@ -1185,7 +1193,7 @@ static void php_cli_server_log_response(php_cli_server_client *client, int statu
}
}
-#if HAVE_UNISTD_H
+#if HAVE_UNISTD_H || defined(PHP_WIN32)
if (CLI_SERVER_G(color) && php_cli_is_output_tty() == OUTPUT_IS_TTY) {
if (effective_status >= 500) {
/* server error: red */