PHP code example of tflori / hugga

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

    

tflori / hugga example snippets




$console = new Hugga\Console;
$name = $console->ask('What is your name?');
$console->line('${fg:white;bg:white;bold}Nice to meet you ' . $name . '!');

$console->line('You will see this', Hugga\Console::WEIGHT_NORMAL);
$console->line('You will not see this', Hugga\Console::WEIGHT_LOWER);
$console->increaseVerbosity();
$console->line('Now you can see this', Hugga\Console::WEIGHT_LOWER);
$console->line('But this is just a debug message', Hugga\Console::WEIGHT_DEBUG);
//$console->setVerbosity(Hugga\Console::WEIGHT_DEBUG);
//$console->debug(
//    ['key' => 'value', 'recursive' => ['string', 42, null, true]],
//    Hugga\Console::DEBUG_PRETTY ^ Hugga\Console::DEBUG_COLOR
// );

$console = new Hugga\Console;

$console->line('Hello world');
$console->write('no newline here');
$console->line('extra detail', Hugga\Console::WEIGHT_LOWER);   // hidden at normal verbosity
$console->increaseVerbosity();                                  // lower threshold — now WEIGHT_LOWER is visible
$console->line('debug dump',   Hugga\Console::WEIGHT_DEBUG);   // still hidden; needs another increaseVerbosity()

$console->info('Operation complete');    // informational, stdout
$console->warn('Disk almost full');      // warning, stderr
$console->error('File not found');       // error, stderr

$console->line('${bold;cyan}Section header');
$console->line('${red}Error:${r} something went wrong');
$console->line('${fg:blue;bg:white}Blue on white');
$console->line('${u}underlined${r} and ${bold}bold${r}');

$console->write('Processing … ${yellow}in progress');
// ... do work ...
$console->delete('in progress');   // removes that exact string
$console->line('${green}done');

$console->write('Loading…');
$console->deleteLine();            // removes the entire current line

$name = $console->ask('What is your name?', 'Anonymous');

if ($console->ask(new Hugga\Input\Question\Confirmation('Are you sure?'))) {
    // confirmed
}

$role = $console->ask(new Hugga\Input\Question\Choice(
    ['admin' => 'Administrator', 'guest' => 'Guest'],
    'Select a role:',
    'guest'   // default
));
// $role === 'admin' or 'guest'

$console->ask(
    (new Hugga\Input\Question\Choice($options, 'Pick one:'))
        ->limit(10)        // show at most 10 options at a time
        ->returnValue()    // return the value instead of the key
);

$table = new Hugga\Output\Drawing\Table($console, [
    ['1', 'Alice', '[email protected]'],
    ['2', 'Bob',   '[email protected]'],
], ['ID', 'Name', 'E-Mail']);

$table->draw();

$table
    ->borders(true)
    ->bordersInside(true)
    ->padding(2)
    ->repeatHeaders(20)
    ->headerStyle('${bold;cyan}')
    ->column(0, ['align' => 'center'])
    ->draw();

$bar = new Hugga\Output\Drawing\ProgressBar($console, 100, 'Importing', 'rows');
$bar->start();
foreach ($rows as $row) {
    process($row);
    $bar->advance();
}
$bar->finish();

$spinner = new Hugga\Output\Drawing\ProgressBar($console, null, 'Waiting for server');
$spinner->start();
// ... poll until done ...
$spinner->template('{title} ${green}done')->finish();

$line  = $console->readLine('$ ');   // prompt + readline with history support
$chars = $console->read(3);          // read exactly 3 characters (multibyte-safe)
$text  = $console->readUntil("\n.\n"); // read until a sentinel string appears

$observer = $console->getInputObserver();
$observer->on("\e", function ($event) use ($observer) {
    $observer->stop();
});
$observer->addHandler(function ($event) {
    echo 'key: ' . $event->char . PHP_EOL;
});
$observer->start();
console
$ php vendor/tflori/hugga/examples/test.php