Skip to content
Suite of tools for demo scripts
PHP
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src
.editorconfig
.gitignore
LICENSE
README.md
composer.json

README.md

Packagist

DemoTools

Suite of tools for demo scripts

Requirements

This tools worj only with PHP7+ for now.

It's using ANSI codes for color management.

Color

The Color interface define some constants to use in terminal messages.

Terminal

The Terminal static class provide some methods to interact with the user with the terminal :

  • cls: Clear screen
  • clear: Clear screen (alias of cls)
  • pause: Wait for user to press a key
  • readUserEntry: Read user entry (with an optional question)
  • printTitle: Print a title
  • menu: display a menu, and return the selected item
  • printColoredLine: print a line with a defined color
  • printSuccess: print a success message (in green by default)
  • printFailure: print a failure message (in red by default)
  • printR: print a dump of all given parameters

cls and clear

Usage:

Terminal::cls():

// or

Terminal::clear();

pause

Usage:

Terminal::pause(); // Display "Press any key to continue..." by default

// or

Terminal::pause('Press a key for next');

readUserEntry

Usage:

$username = Terminal::readUserEntry('Enter your username:');

menu

Usage:

$menuItems = [
    1 => 'Add user',
    2 => 'List users',
    3 => 'Remove user',
    9 => 'Exit'
];

$selectedItem = Terminal::menu($menuItems, 'Manage users:');

Will display:

Manage users:
 - [1] Add user
 - [2] List users
 - [3] Remove user
 - [9] Exit
Your choice: 9

printColoredLine

Usage:

Terminal::printColoredLine('It works', Color::GREEN);

printSuccess

Usage:

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

printFailure

Usage:

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

printR

Used to debug values.

Usage:

Terminal::printR($value1, $value2, $value3);

Menu

Menu is a class used to create an interractive menu. You just need to pass an array of callables:

Usage:

$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.

You can’t perform that action at this time.