Skip to content

Commit 1902f73

Browse files
committed
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
1 parent a1a4c03 commit 1902f73

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

sapi/cli/php_cli_server.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ static php_cli_server_http_response_status_code_pair template_map[] = {
215215

216216
static int php_cli_server_log_level = 3;
217217

218-
#if HAVE_UNISTD_H
218+
#if HAVE_UNISTD_H || defined(PHP_WIN32)
219219
static int php_cli_output_is_tty = OUTPUT_NOT_CHECKED;
220220
#endif
221221

@@ -1160,6 +1160,14 @@ static int php_cli_is_output_tty() /* {{{ */
11601160
}
11611161
return php_cli_output_is_tty;
11621162
} /* }}} */
1163+
#elif defined(PHP_WIN32)
1164+
static int php_cli_is_output_tty() /* {{{ */
1165+
{
1166+
if (php_cli_output_is_tty == OUTPUT_NOT_CHECKED) {
1167+
php_cli_output_is_tty = php_win32_console_fileno_is_console(STDOUT_FILENO) && php_win32_console_fileno_has_vt100(STDOUT_FILENO);
1168+
}
1169+
return php_cli_output_is_tty;
1170+
} /* }}} */
11631171
#endif
11641172

11651173
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
11851193
}
11861194
}
11871195

1188-
#if HAVE_UNISTD_H
1196+
#if HAVE_UNISTD_H || defined(PHP_WIN32)
11891197
if (CLI_SERVER_G(color) && php_cli_is_output_tty() == OUTPUT_IS_TTY) {
11901198
if (effective_status >= 500) {
11911199
/* server error: red */

0 commit comments

Comments
 (0)