PHP code example of tivins / tui

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

    

tivins / tui example snippets


use Tivins\Tui\RotatingColors;
use Tivins\Tui\Throbber;

echo RotatingColors::render('thinking...', $offset) . "\n";

$th = (new Throbber())
    ->message('thinking...')
    ->template('{spinner} {rotating_message}');
// call $th->tick() each frame; optional: $th->rotatingColorOffset()


Tivins\Tui\Frame;
use Tivins\Tui\TermColor;

echo Frame::from("Hello,\nterminal.")
    ->borderStyle(Frame::STYLE_ROUNDED)
    ->borderColor(TermColor::Cyan)
    ->contentColor(TermColor::LightGray)
    ->title('demo', Frame::ALIGN_CENTER)
    ->padding(1)
    ->render() . "\n";

$box = Frame::from('OK')->borderStyle(Frame::STYLE_DOUBLE)->render();

use Tivins\Tui\Frame;
use Tivins\Tui\Layout;
use Tivins\Tui\ProgressBar;

$left = Frame::from("A")->minInnerWidth(8)->render();
$right = Frame::from("B")->minInnerWidth(8)->render();
echo Layout::horizontal([$left, $right], 2) . "\n";

echo ProgressBar::render(37.5, 12) . "\n"; // e.g. ████░░░░░░░░


use Tivins\Tui\Terminal;

$size = Terminal::screenSize(); // ['rows' => ..., 'cols' => ...] or null
Terminal::enterAlternateScreen();
Terminal::clear();
echo "rows: {$size['rows']}\n";

// ...

Terminal::leaveAlternateScreen();

use Tivins\Tui\AsciiText;

$letters = AsciiText::get('hello');
echo AsciiText::toString($letters), "\n";
bash
php tests/terminal.php
php tests/frame_edges.php
php tests/ascii_text.php
php tests/throbber.php
php tests/rotating_colors.php
php tests/layout.php
php tests/progress_bar.php
php tests/ansi_console.php
bash
php tools/generate_future_smooth.php