[Discussion] Native terminal helpers for PHP CLI
| From: | Pratik Bhujel | Date: | Sun, 24 May 2026 17:04:43 +0000 |
| Subject: | [Discussion] Native terminal helpers for PHP CLI | ||
| Groups: | php.internals | ||
| Request: | Send a blank email to internals+get-131004@lists.php.net to get a copy of this message | ||
Hi internals,
I have been experimenting with a small PHP extension for native terminal
helpers:
https://github.com/prateekbhujel/php-terminal
The goal is to expose a small cross-platform CLI terminal layer for the
pieces that are currently awkward to normalize in userland, especially on
Windows:
- checking whether stdin/stdout/stderr are TTYs
- reading terminal size
- enabling/restoring raw mode safely
- reading a single key with normalized names
- writing directly to stdout/stderr
This started from a practical issue with prompt-style PHP CLIs. Laravel
Prompts, for example, currently cannot use its normal interactive prompt
flow on Windows because the backend depends on Unix-style terminal
behavior. I opened a proof-of-concept integration here:
https://github.com/laravel/prompts/pull/242
The extension is still alpha, and I am not proposing it for core right
now. I mainly want feedback on whether this API shape makes sense from a
PHP CLI/runtime point of view, and whether this is better kept as
PECL/ecosystem work first.
Initial release with Windows builds:
https://github.com/prateekbhujel/php-terminal/releases/tag/v0.1.0
If this would be better discussed on internals-win first, I am happy to
move it there. I am mainly looking for feedback on API shape, naming,
Windows behavior, and missing primitives before taking it further.
Thanks,
Pratik