Wallogit.com
2017 © Pedro Peláez
Tools for demo script
Suite of tools for demo scripts, (*2)
This tools worj only with PHP7+ for now., (*3)
It's using ANSI codes for color management., (*4)
The Color interface define some constants to use in terminal messages., (*5)
The Terminal static class provide some methods to interact with the user with the terminal :, (*6)
cls: Clear screenclear: Clear screen (alias of cls)pause: Wait for user to press a keyreadUserEntry: Read user entry (with an optional question)printTitle: Print a titlemenu: display a menu, and return the selected itemprintColoredLine: print a line with a defined colorprintSuccess: print a success message (in green by default)printFailure: print a failure message (in red by default)printR: print a dump of all given parameterscls and clear
Usage:, (*7)
Terminal::cls(): // or Terminal::clear();
pauseUsage:, (*8)
Terminal::pause(); // Display "Press any key to continue..." by default
// or
Terminal::pause('Press a key for next');
readUserEntryUsage:, (*9)
$username = Terminal::readUserEntry('Enter your username:');
menuUsage:, (*10)
$menuItems = [
1 => 'Add user',
2 => 'List users',
3 => 'Remove user',
9 => 'Exit'
];
$selectedItem = Terminal::menu($menuItems, 'Manage users:');
Will display:, (*11)
Manage users: - [1] Add user - [2] List users - [3] Remove user - [9] Exit Your choice: 9
printColoredLineUsage:, (*12)
Terminal::printColoredLine('It works', Color::GREEN);
printSuccessUsage:, (*13)
Terminal::printSuccess(); // Will display 'success' in green
// or
Terminal::printSuccess('done'); // Will display 'done' in green
// or
Terminal::printSuccess('done', Color::BLUE) // Will display 'done' in blue
printFailureUsage:, (*14)
Terminal::printFailure(); // Will display 'failure' in red
// or
Terminal::printFailure('It failed'); // Will display 'It failed' in red
// or
Terminal::printFailure('It failed', Color::BLUE) // Will display 'It failed' in blue
printRUsed to debug values., (*15)
Usage:, (*16)
Terminal::printR($value1, $value2, $value3);
Menu is a class used to create an interractive menu. You just need to pass an array of callables:, (*17)
Usage:, (*18)
$items = [
'Display Hello' = function() { echo 'Hello'; },
'Use callback' = 'MyClass::MyFunction'
];
(new Menu($items))->loop('Choose an option');
It will always add an exit option to the given menu., (*19)