Proposal: Add support for interactive console application on Windows

From: Date: Thu, 12 Oct 2023 23:49:43 +0000
Subject: Proposal: Add support for interactive console application on Windows
Groups: php.internals 
Request: Send a blank email to internals+get-121287@lists.php.net to get a copy of this message
Hi internals 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. Best regards Patrik Pasterčík

« previous php.internals (#121287) next »