PHPackages                             sumpygump/qi-console - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [CLI &amp; Console](/categories/cli)
4. /
5. sumpygump/qi-console

ActiveLibrary[CLI &amp; Console](/categories/cli)

sumpygump/qi-console
====================

Console utilities

1.3.11(3mo ago)594715MITPHPPHP &gt;=7.1CI failing

Since Dec 13Pushed 3mo ago1 watchersCompare

[ Source](https://github.com/sumpygump/qi-console)[ Packagist](https://packagist.org/packages/sumpygump/qi-console)[ Docs](http://quantalideas.com/code/qi-console)[ RSS](/packages/sumpygump-qi-console/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (3)Versions (17)Used By (5)

Qi Console
==========

[](#qi-console)

Qi Console provides PHP library classes for dealing with the console or terminal.

[![Build Status](https://camo.githubusercontent.com/d44233b5ca913dde0bab32dc236913be669eded05c940d128ecda1000de3c44b/68747470733a2f2f7472617669732d63692e6f72672f73756d707967756d702f71692d636f6e736f6c652e706e67)](https://travis-ci.org/sumpygump/qi-console)

Installation with Composer
--------------------------

[](#installation-with-composer)

Use composer to include the `Qi_Console` library in a project.

Add the following composer.json file to your project directory:

```
{
    "require": {
        "sumpygump/qi-console": "dev-master"
    }
}
```

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](http://getcomposer.org/doc/00-intro.md#globally).

```
$ curl -sS https://getcomposer.org/installer | php
$ sudo mv composer.phar /usr/local/bin/composer

```

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.

```
require 'vendor/autoload.php';

$terminal = new Qi_Console_Terminal();
// ...
```

Manual Installation
-------------------

[](#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
=============

[](#documentation)

ArgV
----

[](#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

[](#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:

```
array(
    'myscript.php',
    '-v',
    '--flag',
    '--param=value',
    'okay',
);
```

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 a `Qi_Console_ArgVException`.
- `arg:filename` - a key that begin with the string `arg:` 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. The `arg:`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 first `arg:` key name, etc.

Here is some example code that illustrates the above:

```
// Example rules with some help messages
$rules = array(
    'v' => 'Use verbose messaging',
    'o' => 'Another random option',
    'flag' => 'Flag something as special',
    'name|n:' => 'Provide a name to use',
    'arg:filename' => 'Filename to parse',
);

// Our example input
// php scriptname -v --flag --name "a name" filename.txt
$argv = array(
    'scriptname', // The first argument is always ignored by ArgV
    '-v',
    '--flag',
    '--name',
    '"a name"',
    'filename.txt',
);

$arguments = new Qi_Console_ArgV($argv, $rules);

// Now we can reference the following:
$arguments->v; // true
$arguments->o; // false
$arguments->flag; // true
$arguments->name; // equal to 'a name'
$arguments->filename; // equal to 'filename.txt'
```

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

[](#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

[](#basic-usage)

```
class MyClient extends Qi_Console_Client
{
    public function init()
    {
        // Initialization logic
    }

    public function execute()
    {
        // Execute the main logic of this client
        // Use $this->_args (ArgV object) to handle input and react
        // Use $this->_displayWarning() to output warning message to user
        // etc.
    }
}

$arguments = new Qi_Console_ArgV($argv, $rules);
$terminal = new Qi_Console_Terminal();

$myClient = new MyClient($arguments, $terminal);
$myClient->execute();
```

ExceptionHandler
----------------

[](#exceptionhandler)

The exception handler provides a way to handle exceptions from your console application. It uses the Terminal object to output pretty messages.

```
$terminal = new Qi_Console_Terminal();
$exceptionHandler = new Qi_Console_ExceptionHandler($terminal);
$exceptionHandler->bindHandlers();

// Now any time an exception is thrown, it will output a pretty message
// with colors and exit.
```

Menu
----

[](#menu)

`Qi_Console_Menu` provides a way to prompt a user with a menu and receive input. Please see the code for documentation.

ProgressBar
-----------

[](#progressbar)

`Qi_Console_ProgressBar` provides the ability to display a progress bar in the terminal. Please see the code for documentation.

Std
---

[](#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.

```
// Receive input from STDIN
$input = Qi_Console_Std::in();

// Output to STDOUT
Qi_Console_Std::out('Some text');

// Output to STDERR
Qi_Console_Std::err('Error output');
```

Tabular
-------

[](#tabular)

`Qi_Console_Tabular` generates ascii tables for displaying tabular data.

```
// Define the table data
$tableData = array(
    array('John', '28', 'Green'),
    array('Hannah', '7', 'Violet'),
    array('Michael', '43', 'Red'),
);

// Define the headers for the columns
$headers = array(
    'Name',
    'Age',
    'Favorite Color',
);

// Define optional alignment for columns
$alignment = array(
    'L',
    'R',
    'L'
);

$tabular = new Qi_Console_Tabular(
    $tableData,
    array(
        'headers'   => $headers,
        'cellalign' => $alignment,
    )
);

$tabular->display();
```

This will output the following table:

```
+--------------------------------------+
|  Name     |  Age  |  Favorite Color  |
+--------------------------------------+
|  John     |   28  |  Green           |
|  Hannah   |    7  |  Violet          |
|  Michael  |   43  |  Red             |
+--------------------------------------+

```

Terminal and Terminfo
---------------------

[](#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:

- [Man page for terminfo](http://invisible-island.net/ncurses/man/terminfo.5.html)
- [Terminal Capabilities](https://en.wikipedia.org/wiki/Terminal_capabilities)

### Basic Usage

[](#basic-usage-1)

```
$terminal = new Qi_Console_Terminal();

// Clear the screen
$terminal->clear();

$terminal->set_fgcolor(1);
echo "Text is now red.\n";

$terminal->set_fgcolor(2);
echo "Text is now green.\n";

$terminal->bold_type();
echo "Text is now bold.\n";

$terminal->center_text("This text is centered.");

// This is using the terminfo capability "Original Pair" to set the colors
// back to default.
$terminal->op();
echo "Now text is back to default color.\n";

// This is using the terminfo capability sgr0 which turns off all text
// attributes, meaning it is not bold anymore.
$terminal->sgr0();
echo "Now text is not bold anymore.\n";
```

###  Health Score

49

—

FairBetter than 94% of packages

Maintenance82

Actively maintained with recent releases

Popularity21

Limited adoption so far

Community17

Small or concentrated contributor base

Maturity66

Established project with proven stability

 Bus Factor1

Top contributor holds 92.9% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~347 days

Recently: every ~508 days

Total

15

Last Release

94d ago

PHP version history (2 changes)1.0PHP &gt;=5.3

1.3.1PHP &gt;=7.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/a84a7eefd7bc45723fd004f1424c6183557eea2b82cc7265c739b753cb34d1cf?d=identicon)[sumpygump](/maintainers/sumpygump)

---

Top Contributors

[![sumpygump](https://avatars.githubusercontent.com/u/676007?v=4)](https://github.com/sumpygump "sumpygump (26 commits)")[![jasny](https://avatars.githubusercontent.com/u/100821?v=4)](https://github.com/jasny "jasny (2 commits)")

---

Tags

phpterminalterminfoconsoleterminalterminfo

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/sumpygump-qi-console/health.svg)

```
[![Health](https://phpackages.com/badges/sumpygump-qi-console/health.svg)](https://phpackages.com/packages/sumpygump-qi-console)
```

###  Alternatives

[symfony/console

Eases the creation of beautiful and testable command line interfaces

9.8k1.1B13.9k](/packages/symfony-console)[php-school/cli-menu

A command line menu helper in PHP

1.9k1.2M30](/packages/php-school-cli-menu)[php-tui/php-tui

Comprehensive TUI library heavily influenced by Ratatui

5991.0M15](/packages/php-tui-php-tui)[recca0120/terminal

run laravel artisan command in web application

885419.2k2](/packages/recca0120-terminal)[aplus/cli

Aplus Framework CLI Library

2311.7M6](/packages/aplus-cli)[splitbrain/php-cli

Easy command line scripts for PHP with opt parsing and color output. No dependencies

178866.3k32](/packages/splitbrain-php-cli)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
