On Thu, Oct 12, 2023 at 6:50 PM Patrik Pasterčík <pl...@seznam.cz> wrote:
> I would like to propose extending PHP with support functions to enable > interactive console work on Windows system. I mean the ability to > control a PHP script running from the console using arrow keys, or > function keys like "F1", etc. For example, when a list is displayed to > the user and the user can select the desired item using the arrow keys > and confirm it with the Enter key. > > An analysis of other solutions, a detailed description of the problems > and a proof of concept is in the proposal in the issue here: > https://github.com/php/php-src/issues/12227 > > The short version is that on Linux you can use "fread" function to read > these keys (arrows, etc.) if you use an external `stty` command to set > the console input processing modes (for example the laravel/prompts > package use "stty -icanon -isig -echo"). However, there is no > equivalent of the `stty` command for Windows (without the need to use > the FFI extension, or the need to call an external program to read > pressed keys, see issue for more details), so I propose to extend PHP > with support functions for setting the console input mode > (ENABLE_ECHO_INPUT, ENABLE_LINE_INPUT, ENABLE_PROCESSED_INPUT, > ENABLE_VIRTUAL_TERMINAL_INPUT) by "SetConsoleMode" function, see: > https://learn.microsoft.com/en-us/windows/console/setconsolemode > > I would like to know your opinion on this proposal. Or if you have any > questions. > > And then as a next step I would like to create an RFC proposing these > functions for Windows support. And possibly I could help with > implementation (see my proof of concept in the issue). > > Alternatively, there is the question of whether to generalize this and > directly design a multiplatform API that would allow to read these keys > without the need to use any external programs even on Linux (where > "stty" is used). But I don't know which has a better chance of > implementation, a simple extension for Windows or a more complex > multiplatform solution. > > Resurrecting this message from last October... I think this is a completely reasonable ask, the only bikeshedding I would have is about how we set ourselves up for future success. Specifically, I think there's a space (a small one) for OS-specific functionality. This sort of thing on Windows, exposing CoreFoundation framework utilities on macOS, and probably a whole host of Linux specific toys (oh hey look, we have a posix extension with exactly those things -- yes, I know macOS and windows are posix-ish, don't at me). My point is, I think we should consider `ext/win` (potentially starting in PECL and only later promoting to build-by-default) and use a deliberately chosen prefix namespace like `win_*()`. I plan to open an RFC for this, but I think a temperature check is in order and there were no replies to Patrik's initial email, so this is me shaking the tree. -Sara (re-sent, because php's spam filter, I guess?)