PHP code example of prateekbhujel / php-terminal

1. Go to this page and download the library: Download prateekbhujel/php-terminal 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/ */

    

prateekbhujel / php-terminal example snippets


use Io\Terminal\Key;
use Io\Terminal\Terminal;

$terminal = Terminal::create(); // Standard input and standard output.
$size = $terminal->getSize();
if ($size !== false) {
    echo "{$size->cols} columns, {$size->rows} rows\n";
}

$key = $terminal->readKey(1.0);
if ($key === Key::Up) {
    echo "Up\n";
}

$terminal = Terminal::fromStreams(STDIN, STDERR);
$duplex = Terminal::fromStream($stream);

$terminal = Terminal::fromStreams(STDIN, STDERR);
try {
    $secret = $terminal->readSecret('Password: ');
    $terminal->write("\n");
    // Use $secret without logging it.
} catch (\RuntimeException $e) {
    $terminal->write("\nUnable to read hidden input.\n");
}

$mode = $terminal->enableRawMode();
if ($mode === false) {
    throw new \RuntimeException('Cannot enable raw mode.');
}
try {
    while (($key = $terminal->readKey()) !== false) {
        if ($key === Key::Enter || $key === Key::Escape || $key === "\x03") {
            break;
        }
    }
} finally {
    if (!$terminal->restoreMode()) {
        throw new \RuntimeException('Cannot restore terminal mode.');
    }
}
sh
pie install prateekbhujel/php-terminal:^1.0
php --ri terminal
sh
git clone https://github.com/prateekbhujel/php-terminal.git
cd php-terminal
git checkout v1.1.1
phpize
./configure --with-php-config="$(command -v php-config)"
make -j2
make test REPORT_EXIT_STATUS=1 NO_INTERACTION=1
sudo make install
sh
php -d extension=modules/terminal.so examples/doctor.php
php -d extension=modules/terminal.so examples/prompt.php