1. Go to this page and download the library: Download hoa/console 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/ */
hoa / console example snippets
Hoa\Console\Cursor::move('left left left up up');
Hoa\Console\Cursor::move('← ← ← ↑ ↑');
Hoa\Console\Cursor::moveTo(13, 42);
Hoa\Console\Cursor::save(); // save
Hoa\Console\Cursor::move('↓'); // move below
Hoa\Console\Cursor::clear('↔'); // clear the line
echo 'Something below…'; // write something
Hoa\Console\Cursor::restore(); // restore
$readline = new Hoa\Console\Readline\Readline();
$line = $readline->readLine('> '); // “> ” is the prefix of the line.
$password = new Hoa\Console\Readline\Password();
$line = $password->readLine('password: ');
$readline->addMapping('a', 'z'); // crazy, we replace “a” by “z”.
$readline->addMapping('\C-R', function ($readline) {
// do something when pressing Ctrl-R.
});
$functions = get_defined_functions();
$readline->setAutocompleter(
new Hoa\Console\Readline\Autocompleter\Aggregate([
new Hoa\Console\Readline\Autocompleter\Path(),
new Hoa\Console\Readline\Autocompleter\Word($functions['internal'])
])
);
$processus = new Hoa\Console\Processus('ls');
$processus->open();
echo $processus->readAll();
$processus->writeAll('foobar');
$processus = new Hoa\Console\Processus('ls');
$processus->on('output', function (Hoa\Event\Bucket $bucket) {
$data = $bucket->getData();
echo '> ', $data['line'], "\n";
});
$processus->run();
$parser = new Hoa\Console\Parser();
$parser->parse('-s --long=value input');
$options = new Hoa\Console\GetOption(
[
// long name type short name
// ↓ ↓ ↓
['short', Hoa\Console\GetOption::NO_ARGUMENT, 's'],
['long', Hoa\Console\GetOption::REQUIRED_ARGUMENT, 'l']
],
$parser
);
$short = false;
$long = null;
// short name value
// ↓ ↓
while (false !== $c = $options->getOption($v)) {
switch ($c) {
case 's':
$short = true;
break;
case 'l':
$long = $v;
break;
}
}
var_dump($short, $long); // bool(true) and string(5) "value".
case '__ambiguous':
$options->resolveOptionAmbiguity($v);
break;
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.