Download the PHP package sumpygump/qi-console without Composer
On this page you can find all versions of the php package sumpygump/qi-console. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download sumpygump/qi-console
More information about sumpygump/qi-console
Files in sumpygump/qi-console
Package qi-console
Short Description Console utilities
License MIT
Homepage http://quantalideas.com/code/qi-console
Informations about the package qi-console
Qi Console
Qi Console provides PHP library classes for dealing with the console or terminal.
Installation with Composer
Use composer to include the Qi_Console
library in a project.
Add the following composer.json file to your project directory:
Then run composer install to fetch.
$ composer.phar install
If you don't have composer already installed, this is my recommendation for installing it. See getcomposer.org installation instructions.
Once the files have been composed with the composer install
command, you can
use any of the Qi_Console_
classes after composer's autoloader is included.
Manual Installation
You can also download the files and place them in a library folder. If you do
this, be sure to update your autoloader to handle the Qi_Console_*
classes or
else manually include the files of the classes you'll need.
Documentation
ArgV
ArgV provides a way to assign and gather command line arguments
It will parse and assign option flags and arguments passed in as command line arguments
Examples of script arguments it can potentially parse:
- short option (-f) : can be grouped (-fvz)
- long option (--flag)
- short parameter (-p value)
- short parameter shunt (-pvalue)
- long parameter (--param value)
- long parameter shunt (--param=value)
- standalone argument (filename)
Usage
The constructor takes two arguments: $argv
and $rules
The argument $argv
is an array of arguments from the command line that is parsed by PHP
when the script is invoked. For example, when you invoke a PHP script with the
following:
php myscript.php -v --flag --param=value okay
Then in your script PHP will provide a variable $argv
representative of the
elements of the arguments passed in as an array like this:
The argument $rules
is a definition of options and help messages. The format
is a key value array where the key is the option definition (possible
parameters) and the value is the help message for that option.
Here are some examples illustrating the possible rules keys:
v
- a single letter defines a single short option flag, so this corresponds to the option-v
flag
- a single word defines a long option flag (--flag
)help|h
- a word, then vertical bar, then a single letter will define a long and short option (--help
and-h
)name|n:
- a key that ends with a colon character (:
) indicates a required parameter. This allows the following:--name=value
,-n=value
,--name value
,-n value
and-nvalue
. If the arguments for this option don't contain a parameter this will throw aQi_Console_ArgVException
.arg:filename
- a key that begin with the stringarg:
defines a non-option argument (ones that don't begin with a-
). The word after the colon is the name of the argument as it will appear in ArgV. Thearg:
parameters in$argv
will be assigned in the order they appear in the rules array. So the first non-option argument in$argv
will be assigned to the firstarg:
key name, etc.
Here is some example code that illustrates the above:
Note that any additional options that were not defined in the rules array, but
were passed in as input will result in sensible defaults, so options
will default to true and named options (--anothername=value
) will result in
the values passed in ($arguments->anothername == 'value'
). Additional
non-option arguments will be available as $arguments->__arg2
,
$arguments->__arg3
, etc.
Client
The Qi_Console_Client
class provides a base console client that can be used
to create command line clients. It takes input as $argv
and a Terminal object
which can be used to output messages back to the terminal.
Methods:
__construct()
_displayError()
_displayMessage()
_displayWarning()
_halt()
_resetTty()
_safeExit()
init()
Basic Usage
ExceptionHandler
The exception handler provides a way to handle exceptions from your console application. It uses the Terminal object to output pretty messages.
Menu
Qi_Console_Menu
provides a way to prompt a user with a menu and receive
input. Please see the code for documentation.
ProgressBar
Qi_Console_ProgressBar
provides the ability to display a progress bar in the
terminal. Please see the code for documentation.
Std
Qi_Console_Std
is a wrapper for stdin, stdout and stderr.
This class provides methods for sending and receiving input from stdin and output to stdout and stderr.
Tabular
Qi_Console_Tabular
generates ascii tables for displaying tabular data.
This will output the following table:
+--------------------------------------+
| Name | Age | Favorite Color |
+--------------------------------------+
| John | 28 | Green |
| Hannah | 7 | Violet |
| Michael | 43 | Red |
+--------------------------------------+
Terminal and Terminfo
Qi_Console_Terminal
is a wrapper for Qi_Console_Terminfo
which uses the
UNIX terminfo mapping database to provide functionality for outputting escape
sequences to the terminal. It provides a low-level robust way using terminal
features such as outputting colors.
For more information about terminfo, check out these resources: