Source for file CLI.php
Documentation is available at CLI.php
+----------------------------------------------------------------------+
+----------------------------------------------------------------------+
| Copyright (c) 1997-2004 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.0 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| http://www.php.net/license/3_0.txt. |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| license@php.net so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
+----------------------------------------------------------------------+
$Id: CLI.php,v 1.41 2004/02/17 05:49:16 ssb Exp $
class PEAR_Frontend_CLI extends PEAR
* What type of user interface this frontend is for.
var $lp = ''; // line prefix
function PEAR_Frontend_CLI ()
$term = getenv('TERM'); //(cox) $_ENV is empty for me in 4.1.1
// output is being redirected to a file or through a pipe
// XXX can use ncurses extension here, if available
if (preg_match('/^(xterm|vt220|linux)/', $term)) {
$this->term['bold'] = sprintf("%c%c%c%c", 27 , 91 , 49 , 109 );
$this->term['normal']= sprintf("%c%c%c", 27 , 91 , 109 );
$this->term['bold'] = sprintf("%c%c%c%c%c%c", 27 , 91 , 49 , 109 , 0 , 0 );
$this->term['normal']= sprintf("%c%c%c%c%c", 27 , 91 , 109 , 0 , 0 );
// XXX add ANSI codes here
function displayLine ($text)
trigger_error("PEAR_Frontend_CLI::displayLine deprecated", E_USER_ERROR );
function _displayLine ($text)
print " $this->lp$text\n";
trigger_error("PEAR_Frontend_CLI::display deprecated", E_USER_ERROR );
// {{{ displayError(eobj)
* @param object PEAR_Error object
function displayError ($eobj)
return $this->_displayLine ($eobj->getMessage ());
// {{{ displayFatalError(eobj)
* @param object PEAR_Error object
function displayFatalError ($eobj)
$this->displayError ($eobj);
// {{{ displayHeading(title)
function displayHeading ($title)
trigger_error("PEAR_Frontend_CLI::displayHeading deprecated", E_USER_ERROR );
function _displayHeading ($title)
print $this->lp. $this->bold ($title). "\n";
// {{{ userDialog(prompt, [type], [default])
function userDialog ($command, $prompts, $types = array (), $defaults = array ())
$fp = fopen("php://stdin", "r");
foreach ($prompts as $key => $prompt) {
$default = @$defaults[$key];
if ($type == 'password') {
print " $this->lp$prompt ";
$line = fgets($fp, 2048 );
if ($type == 'password') {
if ($default && trim($line) == "") {
$result[$key] = $default;
// {{{ userConfirm(prompt, [default])
function userConfirm ($prompt, $default = 'yes')
trigger_error("PEAR_Frontend_CLI::userConfirm not yet converted", E_USER_ERROR );
static $positives = array ('y', 'yes', 'on', '1');
static $negatives = array ('n', 'no', 'off', '0');
print " $this->lp $prompt [ $default] : ";
$fp = fopen("php://stdin", "r");
$line = fgets($fp, 2048 );
// {{{ startTable([params])
function startTable ($params = array ())
trigger_error("PEAR_Frontend_CLI::startTable deprecated", E_USER_ERROR );
function _startTable ($params = array ())
$params['table_data'] = array ();
$params['widest'] = array (); // indexed by column
$params['highest'] = array (); // indexed by row
// {{{ tableRow(columns, [rowparams], [colparams])
function tableRow ($columns, $rowparams = array (), $colparams = array ())
trigger_error("PEAR_Frontend_CLI::tableRow deprecated", E_USER_ERROR );
function _tableRow ($columns, $rowparams = array (), $colparams = array ())
for ($i = 0; $i < sizeof($columns); $i++ ) {
if (isset ($colparams[$i]) && !empty ($colparams[$i]['wrap'])) {
$col = wordwrap($col, $colparams[$i]['wrap'], "\n", 0 );
if (strpos($col, "\n") !== false ) {
foreach ($multiline as $n => $line) {
if ($w > @$this->params['widest'][$i]) {
$this->params['widest'][$i] = $w;
// handle unix, mac and windows formats
$lines = (isset ($tmp[10 ]) ? $tmp[10 ] : @$tmp[13 ]) + 1;
if (sizeof($columns) > $this->params['ncols']) {
$this->params['ncols'] = sizeof($columns);
'rowparams' => $rowparams,
'colparams' => $colparams,
$this->params['table_data'][] = $new_row;
trigger_error("PEAR_Frontend_CLI::endTable deprecated", E_USER_ERROR );
$this->_displayHeading ($caption);
if (count($table_data) == 0 ) {
for ($i = 0; $i < $ncols; $i++ ) {
if (!isset ($width[$i])) {
$width[$i] = $widest[$i];
$this->_displayLine ($borderline);
for ($i = 0; $i < sizeof($table_data); $i++ ) {
for ($c = 0; $c < sizeof($data); $c++ ) {
$rowlines[$c] = preg_split('/(\r?\n|\r)/', $data[$c]);
if (sizeof($rowlines[$c]) < $height) {
$rowlines[$c] = array_pad($rowlines[$c], $height, '');
for ($c = 0; $c < sizeof($data); $c++ ) {
$rowlines[$c] = array ($data[$c]);
for ($r = 0; $r < $height; $r++ ) {
for ($c = 0; $c < sizeof($data); $c++ ) {
if (isset ($colparams[$c])) {
$w = isset ($width[$c]) ? $width[$c] : 0;
$cell = $rowlines[$c][$r];
if (isset ($attribs['bold'])) {
$cell = $this->bold ($cell);
// not using str_pad here because we may
// add bold escape characters to $cell
$rowtext .= $cellstart . $cell . $cellend;
$rowtext = rtrim($rowtext);
$this->_displayLine ($rowtext);
$this->_displayLine ($borderline);
function outputData ($data, $command = '_default')
if (isset ($data['release_warnings'])) {
$this->_startTable (array (
'caption' => 'Release Warnings'
$this->_tableRow (array ($data['release_warnings']), null , array (1 => array ('wrap' => 55 )));
$this->_displayLine ($data['data']);
$this->_startTable ($data);
if (isset ($data['headline']) && is_array($data['headline'])) {
$this->_tableRow ($data['headline'], array ('bold' => true ), array (1 => array ('wrap' => 55 )));
foreach($data['data'] as $category) {
foreach($category as $pkg) {
$this->_tableRow ($pkg, null , array (1 => array ('wrap' => 55 )));
$this->_startTable ($data);
if (isset ($data['headline']) && is_array($data['headline'])) {
$this->_tableRow ($data['headline'], array ('bold' => true ), array (1 => array ('wrap' => 55 )));
foreach($data['data'] as $category) {
foreach($category as $pkg) {
$this->_tableRow ($pkg, null , array (1 => array ('wrap' => 55 )));
$opts = array (0 => array ('wrap' => 30 ),
1 => array ('wrap' => 20 ),
2 => array ('wrap' => 35 ));
$this->_startTable ($data);
if (isset ($data['headline']) && is_array($data['headline'])) {
$this->_tableRow ($data['headline'],
foreach($data['data'] as $group) {
foreach($group as $value) {
$this->_tableRow ($value, null , $opts);
'caption' => 'Package details:',
array ("Latest", $data['stable']),
array ("Installed", $data['installed']),
array ("Package", $data['name']),
array ("License", $data['license']),
array ("Category", $data['category']),
array ("Summary", $data['summary']),
array ("Description", $data['description']),
$this->_startTable ($data);
$count = count($data['data'][0 ]);
$opts = array (0 => array ('wrap' => 25 ),
$opts = array (0 => array ('wrap' => 30 ),
1 => array ('wrap' => 20 ),
if (isset ($data['headline']) && is_array($data['headline'])) {
$this->_tableRow ($data['headline'],
foreach($data['data'] as $row) {
$this->_tableRow ($row, null , $opts);
$this->_displayLine ($data);
function log ($text, $append_crlf = true )
return $this->_displayLine ($text);
return $this->_display ($text);
if (empty ($this->term['bold'])) {
return $this->term['bold'] . $text . $this->term['normal'];
Documentation generated on Mon, 11 Mar 2019 14:23:54 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.
|