PHP code example of soloterm / screen

1. Go to this page and download the library: Download soloterm/screen library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

soloterm / screen example snippets


use SoloTerm\Screen\Screen;

// Create a screen with dimensions (columns, rows)
$screen = new Screen(80, 24);

// Write text and ANSI escape sequences
$screen->write("Hello, \e[1;32mWorld!\e[0m");

// Move cursor and add more text
$screen->write("\e[5;10HPositioned text");

// Get the rendered content
echo $screen->output();

$screen = new Screen(80, 24); // width, height
$screen->write("Text and ANSI codes");

use SoloTerm\Screen\Screen;

// Create a screen for a popup/panel
$popup = new Screen(40, 10);
$popup->write("Popup content here...");

// Position the parent terminal's cursor where you want the popup
echo "\e[5;20H";  // Move to row 5, column 20

// Render the popup - it will use relative positioning from this point
echo $popup->output();

$screen = new Screen(80, 24);
$screen->write("Initial content");

// Get the full output and capture the sequence number
$output = $screen->output();
$seqNo = $screen->getLastRenderedSeqNo();

// ... later, after some updates ...
$screen->write("\e[5;1HUpdated line");

// Only get the changed lines (with cursor positioning)
$diff = $screen->output($seqNo);

// Move cursor to position (row 5, column 10)
$screen->write("\e[5;10H");

// Move cursor up 3 lines
$screen->write("\e[3A");

// Save and restore cursor position
$screen->write("\e7"); // Save
$screen->write("More text");
$screen->write("\e8"); // Restore

// Bold red text
$screen->write("\e[1;31mImportant message\e[0m");

// Background colors
$screen->write("\e[44mBlue background\e[0m");

// 256-color support
$screen->write("\e[38;5;208mOrange text\e[0m");

// RGB colors
$screen->write("\e[38;2;255;100;0mCustom color\e[0m");

// Clear screen
$screen->write("\e[2J");

// Clear from cursor to end of line
$screen->write("\e[0K");

// Insert lines
$screen->write("\e[2L");

// Scroll up
$screen->write("\e[2S");

$screen->respondToQueriesVia(function($response) {
    // Process response (like cursor position)
    echo $response;
});

use SoloTerm\Screen\Screen;

$screen = new Screen(80, 24);

// Draw a border
$screen->write("┌" . str_repeat("─", 78) . "┐\n");
for ($i = 0; $i < 22; $i++) {
    $screen->write("│" . str_repeat(" ", 78) . "│\n");
}
$screen->write("└" . str_repeat("─", 78) . "┘");

// Add a title
$screen->write("\e[1;30H\e[1;36mMy Application\e[0m");

// Add some content
$screen->write("\e[5;5HWelcome to the application!");
$screen->write("\e[7;5HPress 'q' to quit.");

// Render
echo $screen->output();

$screen->write("Regular text: Hello");
$screen->write("\nWide characters: 你好世界");
$screen->write("\nEmoji: 🚀 👨‍👩‍👧‍👦 🌍");