php-src/pear/PEAR/CommandUI/CLI.php
Stig Bakken a036fe5b72 * Refactoring of "pear" command internals. Highlights:
- user interface abstraction, making a Gtk installer should only be
   a matter of implementing PEAR_CommandUI_Gtk plus a "pear-gtk" executable
 - separated code into command classes, able to specify one or more
   commands
 - no more "pear-get" :-)
* fixed use of PEAR_Config::singleton to avoid object copying
2002-03-18 17:39:52 +00:00

94 lines
2.0 KiB
PHP

<?php
require_once "PEAR.php";
class PEAR_CommandUI_CLI extends PEAR
{
var $output_mode = 'plain';
var $output_mode_params = array();
function PEAR_CommandUI_CLI()
{
parent::PEAR();
}
function _PEAR_CommandUI_CLI()
{
parent::_PEAR();
if ($this->output_mode) {
$this->endOutput();
}
}
function displayLine($text)
{
print "$text\n";
}
function userDialog($prompt, $type = 'text')
{
if ($type == 'password') {
system('stty -echo');
}
print "$prompt : ";
$fp = fopen("php://stdin", "r");
$line = fgets($fp, 2048);
fclose($fp);
if ($type == 'password') {
system('stty echo');
print "\n";
}
return $line;
}
function userConfirm($prompt, $default = 'yes')
{
static $positives = array('y', 'yes', 'on', '1');
static $negatives = array('n', 'no', 'off', '0');
print "$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;
}
function setOutputMode($mode, $params = array())
{
$this->output_mode = $mode;
$this->output_mode_params = $params;
}
function startOutput($mode)
{
if ($this->output_mode) {
$this->endOutput();
}
switch ($mode) {
}
}
function endOutput($mode = null)
{
if ($mode === null) {
$mode = $this->output_mode;
}
$this->output_mode = '';
switch ($mode) {
}
}
}
?>