Re: [PHP-DEV] Re: [PHP DEV] [Discussion] Native terminal helpers for PHP CLI
[email protected] (Pratik Bhujel)
| Newsgroups | php.internals |
|---|---|
| Message-ID | <CA+9BsNdAjL7tTgZpxq7gYZw=kVPqZDhatfyqpaVM2SQLuHx6qw@mail.gmail.com> |
Hi Rob, hi Tim, @Rob: Thanks for pointing that out! My bad on the broken threads earlier. I was sending from a separate setup that stripped the reference headers. Replying directly via Reply-All now so this stays in the same thread on both the archives and Discourse. @Tim: Thanks a lot for this feedback, it makes total sense. 1. Unifying the streams: You're completely right about stdin/stdout/stderr. Under the hood, the terminal is a single interactive TTY session anyway. Managing them as separate handles just invites state desync and conflicting destructors. I'll consolidate this into a single handle representing the terminal session. e.g. `Terminal::open()` / `Terminal::create()`, plus maybe `Terminal::fromStreams()` if someone needs custom redirection or testing. 2. Named constructors: Got it. I'll switch to the `create*()` / `from*()` prefixes to align with modern core APIs like Dom\HTMLDocument and Time\Duration instead of bare names. 3. OO-only vs procedural: I completely agree. The procedural duplication was carried over from older habits, but since RAII cleanup via the destructor is the entire safety backbone of this extension, an OO-only API (`Io\Terminal\Terminal`) is much cleaner and avoids unnecessary duplication. I'll drop the procedural functions. 4. Redundant getters & discoverability: Dropping `getWidth()` / `getHeight()` in favor of just `$terminal->getSize()` returning a small size object/tuple makes the interface a lot leaner. I'll also make sure the mode methods have clear, grouped naming. I'll start working on these refactors in the codebase and update the RFC draft accordingly. Thanks again for steering this in the right direction! Best, Pratik