2017 © Pedro Peláez
 

library demotools

Tools for demo script

image

jeckel/demotools

Tools for demo script

  • Monday, January 15, 2018
  • by jeckel
  • Repository
  • 1 Watchers
  • 1 Stars
  • 20 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 5 Versions
  • 0 % Grown

The README.md

Packagist, (*1)

DemoTools

Suite of tools for demo scripts, (*2)

Requirements

This tools worj only with PHP7+ for now., (*3)

It's using ANSI codes for color management., (*4)

Color

The Color interface define some constants to use in terminal messages., (*5)

Terminal

The Terminal static class provide some methods to interact with the user with the terminal :, (*6)

  • 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:, (*7)

Terminal::cls():

// or

Terminal::clear();

pause

Usage:, (*8)

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

// or

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

readUserEntry

Usage:, (*9)

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

Usage:, (*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

printColoredLine

Usage:, (*12)

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

printSuccess

Usage:, (*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

printFailure

Usage:, (*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

printR

Used 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)

The Versions

15/01 2018

dev-master

9999999-dev

Tools for demo script

  Sources   Download

MIT

by Julien Mercier

15/01 2018

v0.3.0

0.3.0.0

Tools for demo script

  Sources   Download

MIT

by Julien Mercier

15/01 2018

v0.2.0

0.2.0.0

Tools for demo script

  Sources   Download

MIT

by Julien Mercier

02/01 2018

v0.1.1

0.1.1.0

Tools for demo script

  Sources   Download

MIT

by Julien Mercier

02/01 2018

v0.1.0

0.1.0.0

Tools for demo script

  Sources   Download

MIT

by Julien Mercier