PHP code example of clue / term-react

1. Go to this page and download the library: Download clue/term-react 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/ */

    

clue / term-react example snippets




n = new React\Stream\ReadableResourceStream(STDIN);

$stream = new Clue\React\Term\ControlCodeParser($stdin);

$stream->on('data', function ($chunk) {
    var_dump($chunk);
});

$stream->on('csi', function ($sequence) {
    if ($sequence === "\x1B[A") {
        echo 'cursor UP pressed';
    } else if ($sequence === "\x1B[B") {
        echo 'cursor DOWN pressed';
    }
});

$stream->on('osc', function ($sequence) { … });
$stream->on('apc', function ($sequence) { … });
$stream->on('dps', function ($sequence) { … });
$stream->on('pm', function ($sequence) { … });

$stream->on('c1', function ($sequence) { … });

$stream->on('c0', function ($code) {
    if ($code === "\n") {
        echo 'ENTER pressed';
    }
});