Unable to use ANSI escape code in readline() prompt on Windows
Description
The following code:
$prompt = "\x1b[38;5;203m> \x1b[m";
echo $prompt;
var_dump(readline());
var_dump(readline($prompt));
Resulted in this output: https://user-images.githubusercontent.com/14214667/149023343-3da5830f-b953-4cd7-a1f1-b1a7a769892f.png
But I expected this output instead: https://user-images.githubusercontent.com/14214667/149023371-6ce10901-31c5-4136-aba0-12b343182b93.png
I have not tested this issue on Linux because I never encountered it there.
PHP Version
8.0.13
Operating System
Windows
My brief investigation suggests that the root of the problem lies here, because it accidentally overrides ENABLE_VIRTUAL_TERMINAL_PROCESSING: https://sourceforge.net/p/mingweditline/code/HEAD/tree/mingweditline/trunk/src/editline.c#l1039
However, PHP uses an outdated version of wineditline so it's unclear to me if something else might be causing this.
Further investigation confirms my initial theory. However, there are additional issues with the way wineditline calculates the cursor position even if the flag isn't overridden, since it doesn't know that some characters might be invisible and/or influential to the formatting. I don't know how to fix that.
I've notified the author of wineditline about the issue.
I can confirm your findings. Thanks for the analysis.
So this doesn't look a php-src issue, but is rather wineditline problem. As such, not a bug. I'll leave this ticket open until wineditline has been updated to 2.206, though.
I've notified the author of wineditline about the issue.
Private communication, or is it publicly available?
Private communication, or is it publicly available?
Private email.
The bug does not seem to have been fixed in latest wineditline on sourceforge either. I'm awaiting a response.
Thanks! Please let us know how that conversation goes. :)
wineditline 2.206 has now been deployed (for master branch only), so I'm closing this ticket.
Hi, as I recall wineditline 2.206 was still affected by this issue. PHP was already one version behind when I reported this.
Yes, I know, but the actual issue that you've reported is an upstream issue, so it needs to be solved there.