php-src icon indicating copy to clipboard operation
php-src copied to clipboard

Unable to use ANSI escape code in readline() prompt on Windows

Open dktapps opened this issue 4 years ago • 8 comments

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

dktapps avatar Jan 11 '22 21:01 dktapps

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.

dktapps avatar Jan 11 '22 21:01 dktapps

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.

dktapps avatar Jan 11 '22 23:01 dktapps

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?

cmb69 avatar Jan 12 '22 14:01 cmb69

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.

dktapps avatar Jan 12 '22 15:01 dktapps

Thanks! Please let us know how that conversation goes. :)

cmb69 avatar Jan 12 '22 16:01 cmb69

wineditline 2.206 has now been deployed (for master branch only), so I'm closing this ticket.

cmb69 avatar May 03 '22 16:05 cmb69

Hi, as I recall wineditline 2.206 was still affected by this issue. PHP was already one version behind when I reported this.

dktapps avatar May 03 '22 21:05 dktapps

Yes, I know, but the actual issue that you've reported is an upstream issue, so it needs to be solved there.

cmb69 avatar May 04 '22 08:05 cmb69