I'm in the process of upgrading an old PHP 5 app to PHP 7. I'm using Codeception for unit testing because it has nice colour output, making it easy to see if all the tests have passed or not.
Things I have tried:
- Upgrade to PHP 7: the app crashes
- Run Codeception with no special flags: ANSI escape codes are printed to screen making the output hard to read
- Run Codeception with the
--no-colors
flag: output is a single colour taking longer to recognise a 100% passing run, or which tests have failed - Use ANSICON instead of Windows Command Prompt: PHP 5 runs incredibly slowly, taking an hour to produce a report with coverage, when the same run under the Command Prompt only takes 2 minutes
Things I have not tried:
- Setting a registry value so that ANSI escape codes are always on unless turned of by the running program: this solution is not portable to other developers
I'd like to do the same as the source code listed further below, except within PHP. Something like:
if (is_windows_console()) {
if (has_vt100_extensions()) {
if (are_vt100_extensions_disabled()) {
vt100_extensions->on();
}
}
}
I have no idea if it's even possible to issue commands to the Command Prompt API from within PHP.
The following C code is from the PHP 7 source:
PHP_WINUTIL_API BOOL php_win32_console_fileno_set_vt100(zend_long fileno, BOOL enable)
{
BOOL result = FALSE;
HANDLE handle = (HANDLE) _get_osfhandle(fileno);
if (handle != INVALID_HANDLE_VALUE) {
DWORD events;
if (fileno != 0 && !GetNumberOfConsoleInputEvents(handle, &events)) {
// Not STDIN
DWORD mode;
if (GetConsoleMode(handle, &mode)) {
DWORD newMode;
if (enable) {
newMode = mode | ENABLE_VIRTUAL_TERMINAL_PROCESSING;
}
else {
newMode = mode & ~ENABLE_VIRTUAL_TERMINAL_PROCESSING;
}
if (newMode == mode) {
result = TRUE;
}
else {
if (SetConsoleMode(handle, newMode)) {
result = TRUE;
}
}
}
}
}
return result;
}
Is there a way to emulate this functionality from within a PHP 5 script?
I've found the following related questions but I'm still no closer to even starting: