Screen is a terminal renderer written in pure PHP. It powers Solo for Laravel and
can be used to build rich text-based user interfaces in any PHP application.
Note
Screen is a library intended to be integrated into PHP applications. It is not a standalone terminal application.
A terminal renderer processes text and ANSI escape sequences to create a virtual representation of terminal output.
Unlike a full terminal emulator, Screen focuses specifically on correctly interpreting and rendering text content with
formatting rather than handling input, interactive sessions, or process management.
Terminal renderers interpret escape sequences to:
- Track cursor position
- Apply text colors and styles (bold, underline, etc.)
- Manage screen content
- Handle special character sets
- Generate a final rendered output
Screen implements this functionality in pure PHP, allowing developers to build terminal user interfaces without relying
on external dependencies or native code.
Screen was originally created to solve a specific problem in Solo for Laravel.
Solo provides a TUI (Text User Interface) that runs multiple processes simultaneously in separate panels, similar to
tmux. However, when these processes output ANSI escape codes for cursor movement and screen manipulation, they could
potentially “break out” of their visual containers and interfere with other parts of the interface.
To solve this problem, Screen creates a virtual terminal buffer where:
- All ANSI operations (cursor movements, color changes, screen clears) are safely interpreted within an isolated
environment - The final rendered state is captured after all operations are processed
- Only the final visual output is displayed to the user’s terminal
This approach provides complete control over how terminal output is rendered, ensuring that complex ANSI operations stay
contained within their designated areas. While initially built for Solo, Screen has evolved into a standalone library
that can be used in any PHP application requiring terminal rendering.
- Pure PHP Implementation: Only one dependency (Grapheme, another Solo
library) - Comprehensive ANSI Support: Handles cursor positioning, text styling, and screen manipulation
- Unicode/Multibyte Support: Properly handles UTF-8 characters including emojis and wide characters
- Buffer Management: Maintains separate buffers for text content and styling
- Character Width Handling: Correctly calculates display width for CJK and other double-width characters
- Scrolling: Support for vertical scrolling with proper content management
Install via Composer:
composer require soloterm/screen
- PHP 8.1 or higher
- mbstring extension
Here’s a simple example of using Screen:
Screen operates with several key components:
The main class that coordinates all functionality. It takes care of cursor positioning, content writing, and rendering
the final output.
Screen uses multiple buffer types to track content and styling:
- PrintableBuffer: Stores visible characters and handles width calculations
- AnsiBuffer: Tracks styling information (colors, bold, underline, etc.)
Screen correctly interprets ANSI escape sequences for:
- Cursor movement (up, down, left, right, absolute positioning)
- Text styling (colors, bold, italic, underline)
- Screen clearing and line manipulation
- Scrolling
11 Comments
bschmidt310
[flagged]
cf100clunk
Nice, but your terminal app has a name collision with the long lived ''screen'' terminal multiplexer utility:
https://www.gnu.org/software/screen/manual/screen.html
bschmidt501
[flagged]
bschmidt666
[flagged]
pmarreck
Neat tech demo, but I'd never rely on something like this- I can't help but recall the guy who wrote his own security code for MTGOX which resulted in its getting hacked… Please do not build software that you expect to last in PHP.
As a long-time engineer who's maintained systems across decades, the core problem with PHP isn't that it's "not Turing complete" or "doesn't work"—it's that it encourages entropy.
PHP grew organically from a CGI templating language into a "language" without clear design principles. It’s inconsistent (in_array(needle, haystack) vs array_map(callback, array)), mutability is everywhere, and its type system has historically been an afterthought. The result is code that's often hard to reason about, test, or refactor safely—especially once the original author is long gone.
The classic junior rebuttals— "It powers half the web," "Laravel is great," "Modern PHP is typed!"— miss the point. The issue isn’t what can be done in PHP, it's what PHP encourages by default: global state, poor encapsulation, inconsistent APIs, and difficult-to-enforce discipline. These become cost multipliers over time.
Yes, a disciplined team can write clean, testable PHP. But so can a team using punch cards. The real question is: does the language guide you toward maintainable, composable abstractions or away from them? PHP has historically done the latter. Worse, its community normalized things like: ignoring its own test suite failures, tolerating runtime warnings, etc.
When you're 3 years into maintaining a PHP codebase that five devs with differing levels of discipline have touched, you’ll wish the original author had used nearly anything else.
The older you get, the more you realize "strictness and determinism are primal virtues" in coding.
Use better tools. Your future self will thank you.
Also, as someone else already stated, "screen" the name is already quite taken by another venerable tool. (That tells me you're kind of junior.)
Feel free to downvote away, I don't fucking care, because I spent years working on spaghetticode hell of exactly the sort that PHP encourages.
atarian
I was hoping for an actual desktop app powered by PHP, which would be really cool having PHP as a desktop runtime.
electroly
I'm a little confused–is it an interactive terminal? Or is it more like an ANSI renderer where you are producing a single static image of the final result of printing a series of bytes? I don't see any JavaScript to hint at interactivity.
whalesalad
script kiddies are now going to have high-fidelity shells with 256 colors for when they pwn you and get root on your godaddy drupal install
sidenote: screen is a terrible name for this as there is already gnu/screen (colloquially referred to as screen) which has 38 years head start – https://en.wikipedia.org/wiki/GNU_Screen
also til screen is older than me
throwaway150
Commendable work but note that this is not a terminal emulator. This is a terminal renderer.
mrweasel
Didn't we have this back in 2001. I seems to remember that we kicked a guy of our project because he installed one of the PHP consoles on our Solaris box, which basically gave it the same rights as the Apache user.
aarondf
Thanks for all the feedback! I've updated the readme to use the word "renderer" rather an "emulator."
Gonna stick with the name screen though