From 1902f730ee2bda60552f34c0643e2d7b47e4fb64 Mon Sep 17 00:00:00 2001 From: "Christoph M. Becker" Date: Sun, 16 Aug 2020 17:24:13 +0200 Subject: 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 --- sapi/cli/php_cli_server.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'sapi/cli/php_cli_server.c') 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 */ -- cgit v1.2.1