Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:125533 X-Original-To: internals@lists.php.net Delivered-To: internals@lists.php.net Received: from php-smtp4.php.net (php-smtp4.php.net [45.112.84.5]) by qa.php.net (Postfix) with ESMTPS id 122D31A00CA for ; Fri, 13 Sep 2024 14:08:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1726236611; bh=3bt7ZHRwgzMbp60Gvgmxt1PXY82WMcaFYsgQ6huV/+M=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=VxUERJv+N1OfNOd7tMaPEVChcIB5fJVvFY9m/T8x9hwLAblLQXVuskAZJUUlCv83O qeGlrxsAkc6A+4uet6GayAwyex9G7yhcDj5QfHTW6FM2420Fjkn/tVsrTsOHK2vDW8 w+bghWIqKH/3JcvuXyDOxt4bYFeWLe+Zj7p4UpV3/o2kEJyEa8+ipcP9e3qei2kuny pPPTsczmAHHq4lklaHzlHEJY10ewyLNRrOVkMl2DwWCVhwcC2IqoOrArpv/9JAqJyI uNmfD1RU9aleuU267CoBgpBnYFEbdcx+lpyc2slclfTdo1eQeZT0Tzt9lyK48elFec qJy7KS585lZAw== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 25B8018020B for ; Fri, 13 Sep 2024 14:10:09 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on php-smtp4.php.net X-Spam-Level: *** X-Spam-Status: No, score=3.8 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DMARC_MISSING,HTML_MESSAGE,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_SOFTFAIL autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from mail-ej1-f53.google.com (mail-ej1-f53.google.com [209.85.218.53]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Fri, 13 Sep 2024 14:10:02 +0000 (UTC) Received: by mail-ej1-f53.google.com with SMTP id a640c23a62f3a-a8a6d1766a7so272283466b.3 for ; Fri, 13 Sep 2024 07:07:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=golemon-com.20230601.gappssmtp.com; s=20230601; t=1726236479; x=1726841279; darn=lists.php.net; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=bjxZaXf3NDwSVkMxbluVUUMHkWrMdWFpfGyK9++N32k=; b=h7qAky6Oo7qwuXbc/VsoU3Qf0gupanGx5Va3TMh2Bg6osw0L26I7Ug5Uz4EInZWrUL nEsEkSC1p4MLqUlPhSjYsFrEgOYnScz51ZRa48BhP25KJBxmYraHNOVvI8F4/jNGj4Nw oK6TQ/8xDMxO97DnJfTeJaCRssMr6ICxMsA5Csy8k+zrTrgxu5QlLy6Ugyug37/XznBH j+mmpZ0+M6wCMVgcYzM9FIxzL86xj0L3twAJ53pjQNwVbqs8gIOoPXbqt5oCsZ68uJWH OaFBl8o5gQ2xHYOpylKtv23NI3CyOgxT77EKmLH9JP8l0YV1E/XRu7CPygQgSYeyhBw+ Tt6Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726236479; x=1726841279; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=bjxZaXf3NDwSVkMxbluVUUMHkWrMdWFpfGyK9++N32k=; b=DfxvqvDx97tVOBRCMLjmCwFNWkJlu7B2PXi6CHsJhUiPGyOyHiX9YMUgt+dMh+Z92X 6gGiFIvXgJa4vHU6Up1I/1rwZbzPv4ErCTmuRhZqNGmVbqhGg874D5YysUamSH+7nJqZ eF1q7fVtB78QI/AN6nr1zBqYoiGo5bBAa6GP0rUtd22MbDNa4+pFVmyUkx1e+6V9HCQk FD5TR75kh382Jd+GYyvzQNRmuZuwONVaocX3KUE9yp4yXZrQITn35h1Zr9DbUlCnFpUR IKVFo8fXZpqbVzvnn/jgh+wfPobZnXXWdcmeHrqYkyfozXeV0SUtcLhn04oPTH/i3074 Xgow== X-Gm-Message-State: AOJu0YwX6LdLuxgU7j6DVUZ2TjTzU25tq1VMmd6q6IDI+yR8V4qo7/o6 whH5+oN9WvFSHyuLSywxkoY25A/3kgh5e6viD2gJESaa8Iz5p7Tvnz2+i6d89vE+pVM6eE2RDLV +h3v/lEyd2l+ZoVN2+7jI70amrtIjMi9j3ecjzbtHx6TCrJL7mtY= X-Google-Smtp-Source: AGHT+IGFvjQhQCbpP5HOyRiGoNC6YirnOZNi9EvvewwfK0jggXTUJKFljK/CQI7tL4aGF+7ZR+Ca6ZqqU47dLXfC0EU= X-Received: by 2002:a17:907:e668:b0:a8d:4e26:c9b9 with SMTP id a640c23a62f3a-a902943335emr601647366b.17.1726236477726; Fri, 13 Sep 2024 07:07:57 -0700 (PDT) Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 References: <2CM.F7Wx.3pPEkL6u{51.1bA8ON@seznam.cz> In-Reply-To: <2CM.F7Wx.3pPEkL6u{51.1bA8ON@seznam.cz> Date: Fri, 13 Sep 2024 09:07:46 -0500 Message-ID: Subject: Re: [PHP-DEV] Proposal: Add support for interactive console application on Windows To: =?UTF-8?B?UGF0cmlrIFBhc3RlcsSNw61r?= Cc: internals@lists.php.net Content-Type: multipart/alternative; boundary="0000000000000dbca1062200c002" From: php@golemon.com (Sara Golemon) --0000000000000dbca1062200c002 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Thu, Oct 12, 2023 at 6:50=E2=80=AFPM Patrik Paster=C4=8D=C3=ADk 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?) --0000000000000dbca1062200c002 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
On Thu, Oct 12, 2023 at 6:50=E2=80=AFP= M Patrik Paster=C4=8D=C3=ADk <Plaki@seznam.cz> wrote:
I would like to propose exten= ding PHP with=C2=A0support=C2=A0functions t= o enable
interactive=C2=A0console work o= n Windows system. I mean the ability to
control a PHP script running fro= m the console using arrow keys, or
function keys like "F1", et= c. For example, when a list is displayed to
the user and the user can se= lect 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

T= he 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 usethe FFI extension, or the need to call an external program to read
pre= ssed keys, see issue for more details), so I propose to extend PHP
with= =C2=A0support=C2=A0functions for setting th= e console input mode
(ENABLE_ECHO_INPUT, ENABLE_LINE_INPUT, ENABLE_PROCE= SSED_INPUT,
ENABLE_VIRTUAL_TERMINAL_INPUT) by "SetConsoleMode"= function, see:
https://learn.mic= rosoft.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
f= unctions for Windows=C2=A0support. And poss= ibly I could=C2=A0help=C2=A0with
impleme= ntation (see my proof of concept in the issue).

Alternatively, there= is the question of whether to generalize this and
directly design a mul= tiplatform API that would allow to read these keys
without the need to u= se any external programs even on Linux (where
"stty" is used).= But I don't know which has a better chance of
implementation, a sim= ple extension for Windows or a more complex
multiplatform solution.
<= br>

Resurrecting this message f= rom last October...=C2=A0 I think this is a completely reasonable ask, the = only bikeshedding I would have is about how we set ourselves up for future = success.=C2=A0 Specifically, I think there's a space (a small one) for = OS-specific functionality.=C2=A0 This sort of thing on Windows, exposing Co= reFoundation framework utilities on macOS, and probably a whole host of Lin= ux 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 starti= ng in PECL and only later promoting to build-by-default) and use a delibera= tely chosen prefix namespace like `win_*()`.

I plan to open an RFC f= or this, but I think a temperature check is in order and there were no repl= ies to Patrik's initial email, so this is me shaking the tree.

-Sara

(re-sent, because php's spam filter= , I guess?)
--0000000000000dbca1062200c002--