📄 cli.php
字号:
<?php/* +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ | 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. | +----------------------------------------------------------------------+ | Author: Stig S鎡her Bakken <ssb@php.net> | +----------------------------------------------------------------------+ $Id: CLI.php,v 1.41 2004/02/17 05:49:16 ssb Exp $*/require_once "PEAR.php";class PEAR_Frontend_CLI extends PEAR{ // {{{ properties /** * What type of user interface this frontend is for. * @var string * @access public */ var $type = 'CLI'; var $lp = ''; // line prefix var $params = array(); var $term = array( 'bold' => '', 'normal' => '', ); // }}} // {{{ constructor function PEAR_Frontend_CLI() { parent::PEAR(); $term = getenv('TERM'); //(cox) $_ENV is empty for me in 4.1.1 if (function_exists('posix_isatty') && !posix_isatty(1)) { // output is being redirected to a file or through a pipe } elseif ($term) { // 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); } elseif (preg_match('/^vt100/', $term)) { $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); } } elseif (OS_WINDOWS) { // XXX add ANSI codes here } } // }}} // {{{ displayLine(text) function displayLine($text) { trigger_error("PEAR_Frontend_CLI::displayLine deprecated", E_USER_ERROR); } function _displayLine($text) { print "$this->lp$text\n"; } // }}} // {{{ display(text) function display($text) { trigger_error("PEAR_Frontend_CLI::display deprecated", E_USER_ERROR); } function _display($text) { print $text; } // }}} // {{{ 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); exit(1); } // }}} // {{{ 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"; print $this->lp.str_repeat("=", strlen($title))."\n"; } // }}} // {{{ userDialog(prompt, [type], [default]) function userDialog($command, $prompts, $types = array(), $defaults = array()) { $result = array(); if (is_array($prompts)) { $fp = fopen("php://stdin", "r"); foreach ($prompts as $key => $prompt) { $type = $types[$key]; $default = @$defaults[$key]; if ($type == 'password') { system('stty -echo'); } print "$this->lp$prompt "; if ($default) { print "[$default] "; } print ": "; $line = fgets($fp, 2048); if ($type == 'password') { system('stty echo'); print "\n"; } if ($default && trim($line) == "") { $result[$key] = $default; } else { $result[$key] = $line; } } fclose($fp); } return $result; } // }}} // {{{ 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); fclose($fp); $answer = strtolower(trim($line)); if (empty($answer)) { $answer = $default; } if (in_array($answer, $positives)) { return true; } if (in_array($answer, $negatives)) { return false; } if (in_array($default, $positives)) { return true; } return false; } // }}} // {{{ 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 $params['ncols'] = 0; $this->params = $params; } // }}} // {{{ 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()) { $highest = 1; for ($i = 0; $i < sizeof($columns); $i++) { $col = &$columns[$i]; if (isset($colparams[$i]) && !empty($colparams[$i]['wrap'])) { $col = wordwrap($col, $colparams[$i]['wrap'], "\n", 0); } if (strpos($col, "\n") !== false) { $multiline = explode("\n", $col); $w = 0; foreach ($multiline as $n => $line) { if (strlen($line) > $w) { $w = strlen($line); } } $lines = sizeof($multiline); } else { $w = strlen($col); } if ($w > @$this->params['widest'][$i]) { $this->params['widest'][$i] = $w; } $tmp = count_chars($columns[$i], 1); // handle unix, mac and windows formats $lines = (isset($tmp[10]) ? $tmp[10] : @$tmp[13]) + 1; if ($lines > $highest) { $highest = $lines; } } if (sizeof($columns) > $this->params['ncols']) { $this->params['ncols'] = sizeof($columns); } $new_row = array( 'data' => $columns, 'height' => $highest, 'rowparams' => $rowparams, 'colparams' => $colparams,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -