Subversion Repositories Applications.gtt

Rev

Rev 94 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 94 Rev 187
Line 2... Line 2...
2
/**
2
/**
3
 * PEAR_Frontend_CLI
3
 * PEAR_Frontend_CLI
4
 *
4
 *
5
 * PHP versions 4 and 5
5
 * PHP versions 4 and 5
6
 *
6
 *
7
 * LICENSE: This source file is subject to version 3.0 of the PHP license
-
 
8
 * that is available through the world-wide-web at the following URI:
-
 
9
 * http://www.php.net/license/3_0.txt.  If you did not receive a copy of
-
 
10
 * the PHP License and are unable to obtain it through the web, please
-
 
11
 * send a note to license@php.net so we can mail you a copy immediately.
-
 
12
 *
-
 
13
 * @category   pear
7
 * @category   pear
14
 * @package    PEAR
8
 * @package    PEAR
15
 * @author     Stig Bakken <ssb@php.net>
9
 * @author     Stig Bakken <ssb@php.net>
16
 * @author     Greg Beaver <cellog@php.net>
10
 * @author     Greg Beaver <cellog@php.net>
17
 * @copyright  1997-2006 The PHP Group
11
 * @copyright  1997-2009 The Authors
18
 * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
12
 * @license    http://opensource.org/licenses/bsd-license.php New BSD License
19
 * @version    CVS: $Id: CLI.php,v 1.66 2006/11/19 23:56:32 cellog Exp $
-
 
20
 * @link       http://pear.php.net/package/PEAR
13
 * @link       http://pear.php.net/package/PEAR
21
 * @since      File available since Release 0.1
14
 * @since      File available since Release 0.1
22
 */
15
 */
23
/**
16
/**
24
 * base class
17
 * base class
Line 29... Line 22...
29
 * Command-line Frontend for the PEAR Installer
22
 * Command-line Frontend for the PEAR Installer
30
 * @category   pear
23
 * @category   pear
31
 * @package    PEAR
24
 * @package    PEAR
32
 * @author     Stig Bakken <ssb@php.net>
25
 * @author     Stig Bakken <ssb@php.net>
33
 * @author     Greg Beaver <cellog@php.net>
26
 * @author     Greg Beaver <cellog@php.net>
34
 * @copyright  1997-2006 The PHP Group
27
 * @copyright  1997-2009 The Authors
35
 * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
28
 * @license    http://opensource.org/licenses/bsd-license.php New BSD License
36
 * @version    Release: 1.5.1
29
 * @version    Release: 1.10.1
37
 * @link       http://pear.php.net/package/PEAR
30
 * @link       http://pear.php.net/package/PEAR
38
 * @since      Class available since Release 0.1
31
 * @since      Class available since Release 0.1
39
 */
32
 */
40
class PEAR_Frontend_CLI extends PEAR_Frontend
33
class PEAR_Frontend_CLI extends PEAR_Frontend
41
{
34
{
42
    // {{{ properties
-
 
43
 
-
 
44
    /**
35
    /**
45
     * What type of user interface this frontend is for.
36
     * What type of user interface this frontend is for.
46
     * @var string
37
     * @var string
47
     * @access public
38
     * @access public
48
     */
39
     */
49
    var $type = 'CLI';
40
    var $type = 'CLI';
50
    var $lp = ''; // line prefix
41
    var $lp = ''; // line prefix
Line 51... Line 42...
51
 
42
 
52
    var $params = array();
43
    var $params = array();
53
    var $term = array(
44
    var $term = array(
54
        'bold' => '',
45
        'bold'   => '',
55
        'normal' => '',
46
        'normal' => '',
Line 56... Line -...
56
        );
-
 
57
 
-
 
58
    // }}}
-
 
59
 
-
 
60
    // {{{ constructor
47
    );
61
 
48
 
62
    function PEAR_Frontend_CLI()
49
    function __construct()
63
    {
50
    {
64
        parent::PEAR();
51
        parent::__construct();
65
        $term = getenv('TERM'); //(cox) $_ENV is empty for me in 4.1.1
52
        $term = getenv('TERM'); //(cox) $_ENV is empty for me in 4.1.1
66
        if (function_exists('posix_isatty') && !posix_isatty(1)) {
53
        if (function_exists('posix_isatty') && !posix_isatty(1)) {
67
            // output is being redirected to a file or through a pipe
-
 
68
        } elseif ($term) {
54
            // output is being redirected to a file or through a pipe
69
            // XXX can use ncurses extension here, if available
55
        } elseif ($term) {
70
            if (preg_match('/^(xterm|vt220|linux)/', $term)) {
56
            if (preg_match('/^(xterm|vt220|linux)/', $term)) {
71
                $this->term['bold'] = sprintf("%c%c%c%c", 27, 91, 49, 109);
57
                $this->term['bold']   = sprintf("%c%c%c%c", 27, 91, 49, 109);
72
                $this->term['normal']=sprintf("%c%c%c", 27, 91, 109);
58
                $this->term['normal'] = sprintf("%c%c%c", 27, 91, 109);
73
            } elseif (preg_match('/^vt100/', $term)) {
59
            } elseif (preg_match('/^vt100/', $term)) {
74
                $this->term['bold'] = sprintf("%c%c%c%c%c%c", 27, 91, 49, 109, 0, 0);
60
                $this->term['bold']   = sprintf("%c%c%c%c%c%c", 27, 91, 49, 109, 0, 0);
75
                $this->term['normal']=sprintf("%c%c%c%c%c", 27, 91, 109, 0, 0);
61
                $this->term['normal'] = sprintf("%c%c%c%c%c", 27, 91, 109, 0, 0);
76
            }
62
            }
77
        } elseif (OS_WINDOWS) {
63
        } elseif (OS_WINDOWS) {
78
            // XXX add ANSI codes here
64
            // XXX add ANSI codes here
Line 79... Line -...
79
        }
-
 
80
    }
-
 
81
 
-
 
82
    // }}}
-
 
83
 
-
 
84
    // {{{ displayLine(text)
-
 
85
 
-
 
86
    function displayLine($text)
-
 
87
    {
-
 
88
        trigger_error("PEAR_Frontend_CLI::displayLine deprecated", E_USER_ERROR);
-
 
89
    }
-
 
90
 
-
 
91
    function _displayLine($text)
-
 
92
    {
-
 
93
        print "$this->lp$text\n";
-
 
94
    }
-
 
95
 
-
 
96
    // }}}
-
 
97
    // {{{ display(text)
-
 
98
 
-
 
99
    function display($text)
-
 
100
    {
-
 
101
        trigger_error("PEAR_Frontend_CLI::display deprecated", E_USER_ERROR);
-
 
102
    }
-
 
103
 
-
 
104
    function _display($text)
-
 
105
    {
-
 
106
        print $text;
-
 
107
    }
-
 
108
 
-
 
109
    // }}}
65
        }
110
    // {{{ displayError(eobj)
66
    }
111
 
67
 
112
    /**
68
    /**
113
     * @param object PEAR_Error object
69
     * @param object PEAR_Error object
114
     */
70
     */
115
    function displayError($eobj)
71
    function displayError($e)
Line 116... Line -...
116
    {
-
 
117
        return $this->_displayLine($eobj->getMessage());
-
 
118
    }
-
 
119
 
72
    {
120
    // }}}
73
        return $this->_displayLine($e->getMessage());
121
    // {{{ displayFatalError(eobj)
74
    }
122
 
75
 
123
    /**
76
    /**
Line 129... Line 82...
129
        if (class_exists('PEAR_Config')) {
82
        if (class_exists('PEAR_Config')) {
130
            $config = &PEAR_Config::singleton();
83
            $config = &PEAR_Config::singleton();
131
            if ($config->get('verbose') > 5) {
84
            if ($config->get('verbose') > 5) {
132
                if (function_exists('debug_print_backtrace')) {
85
                if (function_exists('debug_print_backtrace')) {
133
                    debug_print_backtrace();
86
                    debug_print_backtrace();
134
                } elseif (function_exists('debug_backtrace')) {
87
                    exit(1);
135
                    $trace = debug_backtrace();
88
                }
-
 
89
 
136
                    $raised = false;
90
                $raised = false;
137
                    foreach ($trace as $i => $frame) {
91
                foreach (debug_backtrace() as $i => $frame) {
138
                        if (!$raised) {
92
                    if (!$raised) {
139
                            if (isset($frame['class']) && strtolower($frame['class']) ==
-
 
140
                                  'pear' && strtolower($frame['function']) == 'raiseerror') {
-
 
141
                                $raised = true;
-
 
142
                            } else {
-
 
143
                                continue;
-
 
144
                            }
-
 
145
                        }
-
 
146
                        if (!isset($frame['class'])) {
93
                        if (isset($frame['class'])
147
                            $frame['class'] = '';
94
                            && strtolower($frame['class']) == 'pear'
148
                        }
-
 
149
                        if (!isset($frame['type'])) {
-
 
150
                            $frame['type'] = '';
95
                            && strtolower($frame['function']) == 'raiseerror'
151
                        }
96
                        ) {
152
                        if (!isset($frame['function'])) {
-
 
153
                            $frame['function'] = '';
97
                            $raised = true;
154
                        }
98
                        } else {
155
                        if (!isset($frame['line'])) {
-
 
156
                            $frame['line'] = '';
99
                            continue;
157
                        }
100
                        }
158
                        $this->_displayLine("#$i: $frame[class]$frame[type]$frame[function] $frame[line]");
-
 
159
                    }
101
                    }
-
 
102
 
-
 
103
                    $frame['class']    = !isset($frame['class'])    ? '' : $frame['class'];
-
 
104
                    $frame['type']     = !isset($frame['type'])     ? '' : $frame['type'];
-
 
105
                    $frame['function'] = !isset($frame['function']) ? '' : $frame['function'];
-
 
106
                    $frame['line']     = !isset($frame['line'])     ? '' : $frame['line'];
-
 
107
                    $this->_displayLine("#$i: $frame[class]$frame[type]$frame[function] $frame[line]");
160
                }
108
                }
161
            }
109
            }
162
        }
110
        }
163
        exit(1);
-
 
164
    }
-
 
165
 
-
 
166
    // }}}
-
 
167
    // {{{ displayHeading(title)
-
 
168
 
-
 
169
    function displayHeading($title)
-
 
170
    {
-
 
171
        trigger_error("PEAR_Frontend_CLI::displayHeading deprecated", E_USER_ERROR);
-
 
172
    }
-
 
Line 173... Line -...
173
 
-
 
174
    function _displayHeading($title)
111
 
175
    {
-
 
176
        print $this->lp.$this->bold($title)."\n";
-
 
177
        print $this->lp.str_repeat("=", strlen($title))."\n";
112
        exit(1);
Line 178... Line -...
178
    }
-
 
179
 
-
 
180
    // }}}
113
    }
181
 
114
 
182
    /**
115
    /**
183
     * Instruct the runInstallScript method to skip a paramgroup that matches the
116
     * Instruct the runInstallScript method to skip a paramgroup that matches the
184
     * id value passed in.
117
     * id value passed in.
Line 208... Line 141...
208
    function runInstallScript($xml, &$script)
141
    function runInstallScript($xml, &$script)
209
    {
142
    {
210
        $this->_skipSections = array();
143
        $this->_skipSections = array();
211
        if (!is_array($xml) || !isset($xml['paramgroup'])) {
144
        if (!is_array($xml) || !isset($xml['paramgroup'])) {
212
            $script->run(array(), '_default');
145
            $script->run(array(), '_default');
213
        } else {
146
            return;
-
 
147
        }
-
 
148
 
214
            $completedPhases = array();
149
        $completedPhases = array();
215
            if (!isset($xml['paramgroup'][0])) {
150
        if (!isset($xml['paramgroup'][0])) {
216
                $xml['paramgroup'] = array($xml['paramgroup']);
151
            $xml['paramgroup'] = array($xml['paramgroup']);
217
            }
152
        }
-
 
153
 
218
            foreach ($xml['paramgroup'] as $group) {
154
        foreach ($xml['paramgroup'] as $group) {
219
                if (isset($this->_skipSections[$group['id']])) {
155
            if (isset($this->_skipSections[$group['id']])) {
220
                    // the post-install script chose to skip this section dynamically
156
                // the post-install script chose to skip this section dynamically
-
 
157
                continue;
-
 
158
            }
-
 
159
 
-
 
160
            if (isset($group['name'])) {
-
 
161
                $paramname = explode('::', $group['name']);
-
 
162
                if ($lastgroup['id'] != $paramname[0]) {
221
                    continue;
163
                    continue;
222
                }
164
                }
-
 
165
 
223
                if (isset($group['name'])) {
166
                $group['name'] = $paramname[1];
224
                    $paramname = explode('::', $group['name']);
-
 
225
                    if ($lastgroup['id'] != $paramname[0]) {
167
                if (!isset($answers)) {
226
                        continue;
168
                    return;
227
                    }
169
                }
228
                    $group['name'] = $paramname[1];
-
 
229
                    if (isset($answers)) {
-
 
-
 
170
 
230
                        if (isset($answers[$group['name']])) {
171
                if (isset($answers[$group['name']])) {
231
                            switch ($group['conditiontype']) {
172
                    switch ($group['conditiontype']) {
232
                                case '=' :
173
                        case '=' :
233
                                    if ($answers[$group['name']] != $group['value']) {
174
                            if ($answers[$group['name']] != $group['value']) {
234
                                        continue 2;
-
 
235
                                    }
-
 
236
                                break;
-
 
237
                                case '!=' :
-
 
238
                                    if ($answers[$group['name']] == $group['value']) {
-
 
239
                                        continue 2;
-
 
240
                                    }
-
 
241
                                break;
-
 
242
                                case 'preg_match' :
-
 
243
                                    if (!@preg_match('/' . $group['value'] . '/',
-
 
244
                                          $answers[$group['name']])) {
-
 
245
                                        continue 2;
175
                                continue 2;
246
                                    }
-
 
247
                                break;
-
 
248
                                default :
-
 
249
                                return;
-
 
250
                            }
176
                            }
-
 
177
                        break;
-
 
178
                        case '!=' :
-
 
179
                            if ($answers[$group['name']] == $group['value']) {
-
 
180
                                continue 2;
251
                        }
181
                            }
-
 
182
                        break;
-
 
183
                        case 'preg_match' :
-
 
184
                            if (!@preg_match('/' . $group['value'] . '/',
-
 
185
                                  $answers[$group['name']])) {
-
 
186
                                continue 2;
252
                    } else {
187
                            }
-
 
188
                        break;
-
 
189
                        default :
253
                        return;
190
                        return;
254
                    }
191
                    }
255
                }
192
                }
-
 
193
            }
-
 
194
 
256
                $lastgroup = $group;
195
            $lastgroup = $group;
257
                if (isset($group['instructions'])) {
196
            if (isset($group['instructions'])) {
258
                    $this->_display($group['instructions']);
197
                $this->_display($group['instructions']);
259
                }
198
            }
-
 
199
 
260
                if (!isset($group['param'][0])) {
200
            if (!isset($group['param'][0])) {
261
                    $group['param'] = array($group['param']);
201
                $group['param'] = array($group['param']);
262
                }
202
            }
-
 
203
 
263
                if (isset($group['param'])) {
204
            if (isset($group['param'])) {
264
                    if (method_exists($script, 'postProcessPrompts')) {
205
                if (method_exists($script, 'postProcessPrompts')) {
265
                        $prompts = $script->postProcessPrompts($group['param'], $group['id']);
206
                    $prompts = $script->postProcessPrompts($group['param'], $group['id']);
266
                        if (!is_array($prompts) || count($prompts) != count($group['param'])) {
207
                    if (!is_array($prompts) || count($prompts) != count($group['param'])) {
267
                            $this->outputData('postinstall', 'Error: post-install script did not ' .
208
                        $this->outputData('postinstall', 'Error: post-install script did not ' .
268
                                'return proper post-processed prompts');
209
                            'return proper post-processed prompts');
269
                            $prompts = $group['param'];
210
                        $prompts = $group['param'];
270
                        } else {
211
                    } else {
271
                            foreach ($prompts as $i => $var) {
212
                        foreach ($prompts as $i => $var) {
272
                                if (!is_array($var) || !isset($var['prompt']) ||
213
                            if (!is_array($var) || !isset($var['prompt']) ||
273
                                      !isset($var['name']) ||
214
                                  !isset($var['name']) ||
274
                                      ($var['name'] != $group['param'][$i]['name']) ||
215
                                  ($var['name'] != $group['param'][$i]['name']) ||
275
                                      ($var['type'] != $group['param'][$i]['type'])) {
216
                                  ($var['type'] != $group['param'][$i]['type'])
-
 
217
                            ) {
276
                                    $this->outputData('postinstall', 'Error: post-install script ' .
218
                                $this->outputData('postinstall', 'Error: post-install script ' .
277
                                        'modified the variables or prompts, severe security risk. ' .
219
                                    'modified the variables or prompts, severe security risk. ' .
278
                                        'Will instead use the defaults from the package.xml');
220
                                    'Will instead use the defaults from the package.xml');
279
                                    $prompts = $group['param'];
221
                                $prompts = $group['param'];
280
                                }
-
 
281
                            }
222
                            }
282
                        }
223
                        }
283
                        $answers = $this->confirmDialog($prompts);
-
 
284
                    } else {
-
 
285
                        $answers = $this->confirmDialog($group['param']);
-
 
286
                    }
-
 
287
                }
-
 
288
                if ((isset($answers) && $answers) || !isset($group['param'])) {
-
 
289
                    if (!isset($answers)) {
-
 
290
                        $answers = array();
-
 
291
                    }
-
 
292
                    array_unshift($completedPhases, $group['id']);
-
 
293
                    if (!$script->run($answers, $group['id'])) {
-
 
294
                        $script->run($completedPhases, '_undoOnError');
-
 
295
                        return;
-
 
296
                    }
224
                    }
-
 
225
 
-
 
226
                    $answers = $this->confirmDialog($prompts);
297
                } else {
227
                } else {
-
 
228
                    $answers = $this->confirmDialog($group['param']);
-
 
229
                }
-
 
230
            }
-
 
231
 
-
 
232
            if ((isset($answers) && $answers) || !isset($group['param'])) {
-
 
233
                if (!isset($answers)) {
-
 
234
                    $answers = array();
-
 
235
                }
-
 
236
 
-
 
237
                array_unshift($completedPhases, $group['id']);
-
 
238
                if (!$script->run($answers, $group['id'])) {
298
                    $script->run($completedPhases, '_undoOnError');
239
                    $script->run($completedPhases, '_undoOnError');
299
                    return;
240
                    return;
300
                }
241
                }
-
 
242
            } else {
-
 
243
                $script->run($completedPhases, '_undoOnError');
-
 
244
                return;
301
            }
245
            }
302
        }
246
        }
303
    }
247
    }
Line 304... Line 248...
304
 
248
 
Line 308... Line 252...
308
     *              'text to display', 'type' => 'string'[, default => 'default value'])
252
     *              'text to display', 'type' => 'string'[, default => 'default value'])
309
     * @return array
253
     * @return array
310
     */
254
     */
311
    function confirmDialog($params)
255
    function confirmDialog($params)
312
    {
256
    {
313
        $answers = array();
-
 
314
        $prompts = $types = array();
257
        $answers = $prompts = $types = array();
315
        foreach ($params as $param) {
258
        foreach ($params as $param) {
316
            $prompts[$param['name']] = $param['prompt'];
259
            $prompts[$param['name']] = $param['prompt'];
317
            $types[$param['name']] = $param['type'];
260
            $types[$param['name']]   = $param['type'];
318
            if (isset($param['default'])) {
-
 
319
                $answers[$param['name']] = $param['default'];
261
            $answers[$param['name']] = isset($param['default']) ? $param['default'] : '';
320
            } else {
-
 
321
                $answers[$param['name']] = '';
-
 
322
            }
-
 
323
        }
262
        }
-
 
263
 
324
        $tried = false;
264
        $tried = false;
325
        do {
265
        do {
326
            if ($tried) {
266
            if ($tried) {
327
                $i = 1;
267
                $i = 1;
328
                foreach ($answers as $var => $value) {
268
                foreach ($answers as $var => $value) {
Line 330... Line 270...
330
                        echo $this->bold("* Enter an answer for #" . $i . ": ({$prompts[$var]})\n");
270
                        echo $this->bold("* Enter an answer for #" . $i . ": ({$prompts[$var]})\n");
331
                    }
271
                    }
332
                    $i++;
272
                    $i++;
333
                }
273
                }
334
            }
274
            }
-
 
275
 
335
            $answers = $this->userDialog('', $prompts, $types, $answers);
276
            $answers = $this->userDialog('', $prompts, $types, $answers);
336
            $tried = true;
277
            $tried   = true;
337
        } while (is_array($answers) && count(array_filter($answers)) != count($prompts));
278
        } while (is_array($answers) && count(array_filter($answers)) != count($prompts));
-
 
279
 
338
        return $answers;
280
        return $answers;
339
    }
281
    }
340
    // {{{ userDialog(prompt, [type], [default])
-
 
Line 341... Line 282...
341
 
282
 
342
    function userDialog($command, $prompts, $types = array(), $defaults = array(),
-
 
343
                        $screensize = 20)
283
    function userDialog($command, $prompts, $types = array(), $defaults = array(), $screensize = 20)
344
    {
284
    {
345
        if (!is_array($prompts)) {
285
        if (!is_array($prompts)) {
346
            return array();
286
            return array();
-
 
287
        }
347
        }
288
 
348
        $testprompts = array_keys($prompts);
289
        $testprompts = array_keys($prompts);
349
        $result = $defaults;
-
 
350
        if (!defined('STDIN')) {
-
 
351
            $fp = fopen('php://stdin', 'r');
-
 
352
        } else {
-
 
353
            $fp = STDIN;
290
        $result      = $defaults;
354
        }
291
 
355
        reset($prompts);
292
        reset($prompts);
356
        if (count($prompts) == 1 && $types[key($prompts)] == 'yesno') {
293
        if (count($prompts) === 1) {
357
            foreach ($prompts as $key => $prompt) {
294
            foreach ($prompts as $key => $prompt) {
358
                $type = $types[$key];
295
                $type    = $types[$key];
359
                $default = @$defaults[$key];
296
                $default = @$defaults[$key];
360
                print "$prompt ";
297
                print "$prompt ";
361
                if ($default) {
298
                if ($default) {
362
                    print "[$default] ";
299
                    print "[$default] ";
363
                }
300
                }
364
                print ": ";
-
 
365
                if (version_compare(phpversion(), '5.0.0', '<')) {
-
 
366
                    $line = fgets($fp, 2048);
-
 
367
                } else {
-
 
368
                    if (!defined('STDIN')) {
-
 
369
                        define('STDIN', fopen('php://stdin', 'r'));
-
 
-
 
301
                print ": ";
370
                    }
302
 
371
                    $line = fgets(STDIN, 2048);
-
 
372
                }
303
                $line         = fgets(STDIN, 2048);
373
                if ($default && trim($line) == "") {
-
 
374
                    $result[$key] = $default;
-
 
375
                } else {
-
 
376
                    $result[$key] = trim($line);
-
 
377
                }
304
                $result[$key] =  ($default && trim($line) == '') ? $default : trim($line);
-
 
305
            }
378
            }
306
 
379
            return $result;
307
            return $result;
-
 
308
        }
-
 
309
 
380
        }
310
        $first_run = true;
381
        while (true) {
311
        while (true) {
382
            $descLength = max(array_map('strlen', $prompts));
312
            $descLength = max(array_map('strlen', $prompts));
383
            $descFormat = "%-{$descLength}s";
313
            $descFormat = "%-{$descLength}s";
Line 384... Line 314...
384
            $last = count($prompts);
314
            $last       = count($prompts);
385
 
315
 
386
            $i = 0;
316
            $i = 0;
387
            foreach ($prompts as $n => $var) {
317
            foreach ($prompts as $n => $var) {
388
                printf("%2d. $descFormat : %s\n", ++$i, $prompts[$n], isset($result[$n]) ?
318
                $res = isset($result[$n]) ? $result[$n] : null;
389
                    $result[$n] : null);
-
 
390
            }
319
                printf("%2d. $descFormat : %s\n", ++$i, $prompts[$n], $res);
-
 
320
            }
391
 
321
            print "\n1-$last, 'all', 'abort', or Enter to continue: ";
392
            print "\n1-$last, 'all', 'abort', or Enter to continue: ";
322
 
393
            $tmp = trim(fgets($fp, 1024));
323
            $tmp = trim(fgets(STDIN, 1024));
394
            if (empty($tmp)) {
324
            if (empty($tmp)) {
-
 
325
                break;
395
                break;
326
            }
396
            }
327
 
397
            if ($tmp == 'abort') {
328
            if ($tmp == 'abort') {
-
 
329
                return false;
398
                return false;
330
            }
399
            }
331
 
400
            if (isset($testprompts[(int)$tmp - 1])) {
332
            if (isset($testprompts[(int)$tmp - 1])) {
401
                $var = $testprompts[(int)$tmp - 1];
333
                $var     = $testprompts[(int)$tmp - 1];
402
                $desc = $prompts[$var];
334
                $desc    = $prompts[$var];
403
                $current = @$result[$var];
335
                $current = @$result[$var];
404
                print "$desc [$current] : ";
336
                print "$desc [$current] : ";
405
                $tmp = trim(fgets($fp, 1024));
337
                $tmp = trim(fgets(STDIN, 1024));
406
                if (trim($tmp) !== '') {
338
                if ($tmp !== '') {
407
                    $result[$var] = trim($tmp);
339
                    $result[$var] = $tmp;
408
                }
340
                }
409
            } elseif ($tmp == 'all') {
341
            } elseif ($tmp == 'all') {
410
                foreach ($prompts as $var => $desc) {
342
                foreach ($prompts as $var => $desc) {
411
                    $current = $result[$var];
343
                    $current = $result[$var];
412
                    print "$desc [$current] : ";
344
                    print "$desc [$current] : ";
413
                    $tmp = trim(fgets($fp, 1024));
345
                    $tmp = trim(fgets(STDIN, 1024));
414
                    if (trim($tmp) !== '') {
346
                    if (trim($tmp) !== '') {
415
                        $result[$var] = trim($tmp);
347
                        $result[$var] = trim($tmp);
416
                    }
348
                    }
-
 
349
                }
-
 
350
            }
417
                }
351
 
418
            }
-
 
419
        }
-
 
420
        if (!defined('STDIN')) {
352
            $first_run = false;
421
            fclose($fp);
353
        }
422
        }
354
 
Line 423... Line -...
423
        return $result;
-
 
424
    }
-
 
425
 
-
 
426
    // }}}
355
        return $result;
427
    // {{{ userConfirm(prompt, [default])
356
    }
428
 
357
 
429
    function userConfirm($prompt, $default = 'yes')
358
    function userConfirm($prompt, $default = 'yes')
430
    {
359
    {
Line 449... Line 378...
449
            return true;
378
            return true;
450
        }
379
        }
451
        return false;
380
        return false;
452
    }
381
    }
Line -... Line 382...
-
 
382
 
453
 
383
    function outputData($data, $command = '_default')
-
 
384
    {
-
 
385
        switch ($command) {
-
 
386
            case 'channel-info':
-
 
387
                foreach ($data as $type => $section) {
-
 
388
                    if ($type == 'main') {
-
 
389
                        $section['data'] = array_values($section['data']);
-
 
390
                    }
-
 
391
 
-
 
392
                    $this->outputData($section);
-
 
393
                }
-
 
394
                break;
-
 
395
            case 'install':
-
 
396
            case 'upgrade':
-
 
397
            case 'upgrade-all':
-
 
398
                if (is_array($data) && isset($data['release_warnings'])) {
-
 
399
                    $this->_displayLine('');
-
 
400
                    $this->_startTable(array(
-
 
401
                        'border' => false,
-
 
402
                        'caption' => 'Release Warnings'
-
 
403
                    ));
-
 
404
                    $this->_tableRow(array($data['release_warnings']), null, array(1 => array('wrap' => 55)));
-
 
405
                    $this->_endTable();
-
 
406
                    $this->_displayLine('');
-
 
407
                }
-
 
408
 
-
 
409
                $this->_displayLine(is_array($data) ? $data['data'] : $data);
-
 
410
                break;
454
    // }}}
411
            case 'search':
-
 
412
                $this->_startTable($data);
-
 
413
                if (isset($data['headline']) && is_array($data['headline'])) {
-
 
414
                    $this->_tableRow($data['headline'], array('bold' => true), array(1 => array('wrap' => 55)));
-
 
415
                }
-
 
416
 
-
 
417
                $packages = array();
-
 
418
                foreach($data['data'] as $category) {
-
 
419
                    foreach($category as $name => $pkg) {
-
 
420
                        $packages[$pkg[0]] = $pkg;
-
 
421
                    }
-
 
422
                }
-
 
423
 
-
 
424
                $p = array_keys($packages);
-
 
425
                natcasesort($p);
-
 
426
                foreach ($p as $name) {
-
 
427
                    $this->_tableRow($packages[$name], null, array(1 => array('wrap' => 55)));
Line -... Line 428...
-
 
428
                }
-
 
429
 
-
 
430
                $this->_endTable();
-
 
431
                break;
-
 
432
            case 'list-all':
-
 
433
                if (!isset($data['data'])) {
-
 
434
                      $this->_displayLine('No packages in channel');
-
 
435
                      break;
-
 
436
                }
-
 
437
 
-
 
438
                $this->_startTable($data);
-
 
439
                if (isset($data['headline']) && is_array($data['headline'])) {
-
 
440
                    $this->_tableRow($data['headline'], array('bold' => true), array(1 => array('wrap' => 55)));
-
 
441
                }
-
 
442
 
-
 
443
                $packages = array();
-
 
444
                foreach($data['data'] as $category) {
-
 
445
                    foreach($category as $name => $pkg) {
-
 
446
                        $packages[$pkg[0]] = $pkg;
-
 
447
                    }
-
 
448
                }
-
 
449
 
-
 
450
                $p = array_keys($packages);
-
 
451
                natcasesort($p);
-
 
452
                foreach ($p as $name) {
-
 
453
                    $pkg = $packages[$name];
-
 
454
                    unset($pkg[4], $pkg[5]);
-
 
455
                    $this->_tableRow($pkg, null, array(1 => array('wrap' => 55)));
-
 
456
                }
-
 
457
 
-
 
458
                $this->_endTable();
-
 
459
                break;
-
 
460
            case 'config-show':
-
 
461
                $data['border'] = false;
-
 
462
                $opts = array(
-
 
463
                    0 => array('wrap' => 30),
-
 
464
                    1 => array('wrap' => 20),
-
 
465
                    2 => array('wrap' => 35)
-
 
466
                );
-
 
467
 
-
 
468
                $this->_startTable($data);
-
 
469
                if (isset($data['headline']) && is_array($data['headline'])) {
-
 
470
                    $this->_tableRow($data['headline'], array('bold' => true), $opts);
-
 
471
                }
-
 
472
 
-
 
473
                foreach ($data['data'] as $group) {
-
 
474
                    foreach ($group as $value) {
-
 
475
                        if ($value[2] == '') {
-
 
476
                            $value[2] = "<not set>";
-
 
477
                        }
-
 
478
 
-
 
479
                        $this->_tableRow($value, null, $opts);
-
 
480
                    }
-
 
481
                }
-
 
482
 
-
 
483
                $this->_endTable();
-
 
484
                break;
-
 
485
            case 'remote-info':
-
 
486
                $d = $data;
-
 
487
                $data = array(
-
 
488
                    'caption' => 'Package details:',
-
 
489
                    'border'  => false,
-
 
490
                    'data'    => array(
-
 
491
                        array("Latest",      $data['stable']),
-
 
492
                        array("Installed",   $data['installed']),
-
 
493
                        array("Package",     $data['name']),
-
 
494
                        array("License",     $data['license']),
-
 
495
                        array("Category",    $data['category']),
-
 
496
                        array("Summary",     $data['summary']),
-
 
497
                        array("Description", $data['description']),
-
 
498
                    ),
-
 
499
                );
-
 
500
 
-
 
501
                if (isset($d['deprecated']) && $d['deprecated']) {
-
 
502
                    $conf = &PEAR_Config::singleton();
-
 
503
                    $reg = $conf->getRegistry();
-
 
504
                    $name = $reg->parsedPackageNameToString($d['deprecated'], true);
-
 
505
                    $data['data'][] = array('Deprecated! use', $name);
-
 
506
                }
-
 
507
            default: {
-
 
508
                if (is_array($data)) {
-
 
509
                    $this->_startTable($data);
-
 
510
                    $count = count($data['data'][0]);
-
 
511
                    if ($count == 2) {
-
 
512
                        $opts = array(0 => array('wrap' => 25),
-
 
513
                                      1 => array('wrap' => 48)
-
 
514
                        );
-
 
515
                    } elseif ($count == 3) {
-
 
516
                        $opts = array(0 => array('wrap' => 30),
-
 
517
                                      1 => array('wrap' => 20),
-
 
518
                                      2 => array('wrap' => 35)
-
 
519
                        );
-
 
520
                    } else {
-
 
521
                        $opts = null;
-
 
522
                    }
-
 
523
                    if (isset($data['headline']) && is_array($data['headline'])) {
-
 
524
                        $this->_tableRow($data['headline'],
-
 
525
                                         array('bold' => true),
-
 
526
                                         $opts);
-
 
527
                    }
-
 
528
 
-
 
529
                    if (is_array($data['data'])) {
-
 
530
                        foreach($data['data'] as $row) {
-
 
531
                            $this->_tableRow($row, null, $opts);
-
 
532
                        }
-
 
533
                    } else {
-
 
534
                        $this->_tableRow(array($data['data']), null, $opts);
-
 
535
                     }
-
 
536
                    $this->_endTable();
-
 
537
                } else {
-
 
538
                    $this->_displayLine($data);
-
 
539
                }
-
 
540
            }
-
 
541
        }
455
    // {{{ startTable([params])
542
    }
456
 
543
 
-
 
544
    function log($text, $append_crlf = true)
457
    function startTable($params = array())
545
    {
-
 
546
        if ($append_crlf) {
-
 
547
            return $this->_displayLine($text);
-
 
548
        }
458
    {
549
 
Line 459... Line 550...
459
        trigger_error("PEAR_Frontend_CLI::startTable deprecated", E_USER_ERROR);
550
        return $this->_display($text);
460
    }
551
    }
461
 
552
 
462
    function _startTable($params = array())
-
 
463
    {
553
    function bold($text)
464
        $params['table_data'] = array();
554
    {
-
 
555
        if (empty($this->term['bold'])) {
465
        $params['widest'] = array();  // indexed by column
556
            return strtoupper($text);
466
        $params['highest'] = array(); // indexed by row
557
        }
Line -... Line 558...
-
 
558
 
467
        $params['ncols'] = 0;
559
        return $this->term['bold'] . $text . $this->term['normal'];
-
 
560
    }
468
        $this->params = $params;
561
 
-
 
562
    function _displayHeading($title)
Line 469... Line 563...
469
    }
563
    {
470
 
564
        print $this->lp.$this->bold($title)."\n";
-
 
565
        print $this->lp.str_repeat("=", strlen($title))."\n";
471
    // }}}
566
    }
-
 
567
 
-
 
568
    function _startTable($params = array())
-
 
569
    {
472
    // {{{ tableRow(columns, [rowparams], [colparams])
570
        $params['table_data'] = array();
Line 473... Line 571...
473
 
571
        $params['widest']     = array();  // indexed by column
474
    function tableRow($columns, $rowparams = array(), $colparams = array())
572
        $params['highest']    = array(); // indexed by row
475
    {
573
        $params['ncols']      = 0;
476
        trigger_error("PEAR_Frontend_CLI::tableRow deprecated", E_USER_ERROR);
574
        $this->params         = $params;
477
    }
575
    }
478
 
576
 
479
    function _tableRow($columns, $rowparams = array(), $colparams = array())
577
    function _tableRow($columns, $rowparams = array(), $colparams = array())
480
    {
578
    {
-
 
579
        $highest = 1;
481
        $highest = 1;
580
        for ($i = 0; $i < count($columns); $i++) {
482
        for ($i = 0; $i < sizeof($columns); $i++) {
581
            $col = &$columns[$i];
483
            $col = &$columns[$i];
582
            if (isset($colparams[$i]) && !empty($colparams[$i]['wrap'])) {
484
            if (isset($colparams[$i]) && !empty($colparams[$i]['wrap'])) {
583
                $col = wordwrap($col, $colparams[$i]['wrap']);
-
 
584
            }
485
                $col = wordwrap($col, $colparams[$i]['wrap'], "\n", 0);
585
 
486
            }
586
            if (strpos($col, "\n") !== false) {
487
            if (strpos($col, "\n") !== false) {
587
                $multiline = explode("\n", $col);
488
                $multiline = explode("\n", $col);
588
                $w = 0;
489
                $w = 0;
589
                foreach ($multiline as $n => $line) {
490
                foreach ($multiline as $n => $line) {
590
                    $len = strlen($line);
491
                    if (strlen($line) > $w) {
591
                    if ($len > $w) {
492
                        $w = strlen($line);
592
                        $w = $len;
Line 493... Line 593...
493
                    }
593
                    }
Line 502... Line 602...
502
                    $this->params['widest'][$i] = $w;
602
                    $this->params['widest'][$i] = $w;
503
                }
603
                }
504
            } else {
604
            } else {
505
                $this->params['widest'][$i] = $w;
605
                $this->params['widest'][$i] = $w;
506
            }
606
            }
-
 
607
 
507
            $tmp = count_chars($columns[$i], 1);
608
            $tmp = count_chars($columns[$i], 1);
508
            // handle unix, mac and windows formats
609
            // handle unix, mac and windows formats
509
            $lines = (isset($tmp[10]) ? $tmp[10] : (isset($tmp[13]) ? $tmp[13] : 0)) + 1;
610
            $lines = (isset($tmp[10]) ? $tmp[10] : (isset($tmp[13]) ? $tmp[13] : 0)) + 1;
510
            if ($lines > $highest) {
611
            if ($lines > $highest) {
511
                $highest = $lines;
612
                $highest = $lines;
512
            }
613
            }
513
        }
614
        }
-
 
615
 
514
        if (sizeof($columns) > $this->params['ncols']) {
616
        if (count($columns) > $this->params['ncols']) {
515
            $this->params['ncols'] = sizeof($columns);
617
            $this->params['ncols'] = count($columns);
516
        }
618
        }
-
 
619
 
517
        $new_row = array(
620
        $new_row = array(
518
            'data' => $columns,
621
            'data'      => $columns,
519
            'height' => $highest,
622
            'height'    => $highest,
520
            'rowparams' => $rowparams,
623
            'rowparams' => $rowparams,
521
            'colparams' => $colparams,
624
            'colparams' => $colparams,
522
            );
625
        );
523
        $this->params['table_data'][] = $new_row;
626
        $this->params['table_data'][] = $new_row;
524
    }
627
    }
Line 525... Line -...
525
 
-
 
526
    // }}}
-
 
527
    // {{{ endTable()
-
 
528
 
-
 
529
    function endTable()
-
 
530
    {
-
 
531
        trigger_error("PEAR_Frontend_CLI::endTable deprecated", E_USER_ERROR);
-
 
532
    }
-
 
533
 
628
 
534
    function _endTable()
629
    function _endTable()
535
    {
630
    {
536
        extract($this->params);
631
        extract($this->params);
537
        if (!empty($caption)) {
632
        if (!empty($caption)) {
538
            $this->_displayHeading($caption);
633
            $this->_displayHeading($caption);
-
 
634
        }
539
        }
635
 
540
        if (count($table_data) == 0) {
636
        if (count($table_data) === 0) {
541
            return;
637
            return;
-
 
638
        }
542
        }
639
 
543
        if (!isset($width)) {
640
        if (!isset($width)) {
544
            $width = $widest;
641
            $width = $widest;
545
        } else {
642
        } else {
546
            for ($i = 0; $i < $ncols; $i++) {
643
            for ($i = 0; $i < $ncols; $i++) {
547
                if (!isset($width[$i])) {
644
                if (!isset($width[$i])) {
548
                    $width[$i] = $widest[$i];
645
                    $width[$i] = $widest[$i];
549
                }
646
                }
550
            }
647
            }
-
 
648
        }
551
        }
649
 
552
        $border = false;
650
        $border = false;
553
        if (empty($border)) {
651
        if (empty($border)) {
554
            $cellstart = '';
652
            $cellstart  = '';
555
            $cellend = ' ';
653
            $cellend    = ' ';
556
            $rowend = '';
654
            $rowend     = '';
557
            $padrowend = false;
655
            $padrowend  = false;
558
            $borderline = '';
656
            $borderline = '';
559
        } else {
657
        } else {
560
            $cellstart = '| ';
658
            $cellstart  = '| ';
561
            $cellend = ' ';
659
            $cellend    = ' ';
562
            $rowend = '|';
660
            $rowend     = '|';
563
            $padrowend = true;
661
            $padrowend  = true;
564
            $borderline = '+';
662
            $borderline = '+';
565
            foreach ($width as $w) {
663
            foreach ($width as $w) {
566
                $borderline .= str_repeat('-', $w + strlen($cellstart) + strlen($cellend) - 1);
664
                $borderline .= str_repeat('-', $w + strlen($cellstart) + strlen($cellend) - 1);
567
                $borderline .= '+';
665
                $borderline .= '+';
568
            }
666
            }
-
 
667
        }
569
        }
668
 
570
        if ($borderline) {
669
        if ($borderline) {
571
            $this->_displayLine($borderline);
670
            $this->_displayLine($borderline);
-
 
671
        }
572
        }
672
 
573
        for ($i = 0; $i < sizeof($table_data); $i++) {
673
        for ($i = 0; $i < count($table_data); $i++) {
574
            extract($table_data[$i]);
674
            extract($table_data[$i]);
575
            if (!is_array($rowparams)) {
675
            if (!is_array($rowparams)) {
576
                $rowparams = array();
676
                $rowparams = array();
-
 
677
            }
577
            }
678
 
578
            if (!is_array($colparams)) {
679
            if (!is_array($colparams)) {
579
                $colparams = array();
680
                $colparams = array();
-
 
681
            }
580
            }
682
 
581
            $rowlines = array();
683
            $rowlines = array();
582
            if ($height > 1) {
684
            if ($height > 1) {
583
                for ($c = 0; $c < sizeof($data); $c++) {
685
                for ($c = 0; $c < count($data); $c++) {
584
                    $rowlines[$c] = preg_split('/(\r?\n|\r)/', $data[$c]);
686
                    $rowlines[$c] = preg_split('/(\r?\n|\r)/', $data[$c]);
585
                    if (sizeof($rowlines[$c]) < $height) {
687
                    if (count($rowlines[$c]) < $height) {
586
                        $rowlines[$c] = array_pad($rowlines[$c], $height, '');
688
                        $rowlines[$c] = array_pad($rowlines[$c], $height, '');
587
                    }
689
                    }
588
                }
690
                }
589
            } else {
691
            } else {
590
                for ($c = 0; $c < sizeof($data); $c++) {
692
                for ($c = 0; $c < count($data); $c++) {
591
                    $rowlines[$c] = array($data[$c]);
693
                    $rowlines[$c] = array($data[$c]);
592
                }
694
                }
-
 
695
            }
593
            }
696
 
594
            for ($r = 0; $r < $height; $r++) {
697
            for ($r = 0; $r < $height; $r++) {
595
                $rowtext = '';
698
                $rowtext = '';
596
                for ($c = 0; $c < sizeof($data); $c++) {
699
                for ($c = 0; $c < count($data); $c++) {
597
                    if (isset($colparams[$c])) {
700
                    if (isset($colparams[$c])) {
598
                        $attribs = array_merge($rowparams, $colparams);
701
                        $attribs = array_merge($rowparams, $colparams);
599
                    } else {
702
                    } else {
600
                        $attribs = $rowparams;
703
                        $attribs = $rowparams;
-
 
704
                    }
601
                    }
705
 
602
                    $w = isset($width[$c]) ? $width[$c] : 0;
706
                    $w = isset($width[$c]) ? $width[$c] : 0;
603
                    //$cell = $data[$c];
707
                    //$cell = $data[$c];
604
                    $cell = $rowlines[$c][$r];
708
                    $cell = $rowlines[$c][$r];
605
                    $l = strlen($cell);
709
                    $l = strlen($cell);
606
                    if ($l > $w) {
710
                    if ($l > $w) {
607
                        $cell = substr($cell, 0, $w);
711
                        $cell = substr($cell, 0, $w);
-
 
712
                    }
608
                    }
713
 
609
                    if (isset($attribs['bold'])) {
714
                    if (isset($attribs['bold'])) {
610
                        $cell = $this->bold($cell);
715
                        $cell = $this->bold($cell);
-
 
716
                    }
611
                    }
717
 
612
                    if ($l < $w) {
718
                    if ($l < $w) {
613
                        // not using str_pad here because we may
719
                        // not using str_pad here because we may
614
                        // add bold escape characters to $cell
720
                        // add bold escape characters to $cell
615
                        $cell .= str_repeat(' ', $w - $l);
721
                        $cell .= str_repeat(' ', $w - $l);
Line 616... Line 722...
616
                    }
722
                    }
617
 
723
 
-
 
724
                    $rowtext .= $cellstart . $cell . $cellend;
618
                    $rowtext .= $cellstart . $cell . $cellend;
725
                }
619
                }
726
 
620
                if (!$border) {
727
                if (!$border) {
-
 
728
                    $rowtext = rtrim($rowtext);
621
                    $rowtext = rtrim($rowtext);
729
                }
622
                }
730
 
623
                $rowtext .= $rowend;
731
                $rowtext .= $rowend;
624
                $this->_displayLine($rowtext);
732
                $this->_displayLine($rowtext);
-
 
733
            }
625
            }
734
        }
626
        }
735
 
627
        if ($borderline) {
736
        if ($borderline) {
628
            $this->_displayLine($borderline);
737
            $this->_displayLine($borderline);
Line 629... Line -...
629
        }
-
 
630
    }
-
 
631
 
-
 
632
    // }}}
-
 
633
    // {{{ outputData()
-
 
634
 
-
 
635
    function outputData($data, $command = '_default')
-
 
636
    {
-
 
637
        switch ($command) {
-
 
638
            case 'channel-info':
-
 
639
                foreach ($data as $type => $section) {
-
 
640
                    if ($type == 'main') {
-
 
641
                        $section['data'] = array_values($section['data']);
-
 
642
                    }
-
 
643
                    $this->outputData($section);
-
 
644
                }
-
 
645
                break;
-
 
646
            case 'install':
-
 
647
            case 'upgrade':
-
 
648
            case 'upgrade-all':
-
 
649
                if (isset($data['release_warnings'])) {
-
 
650
                    $this->_displayLine('');
-
 
651
                    $this->_startTable(array(
-
 
652
                        'border' => false,
-
 
653
                        'caption' => 'Release Warnings'
-
 
654
                        ));
-
 
655
                    $this->_tableRow(array($data['release_warnings']), null, array(1 => array('wrap' => 55)));
-
 
656
                    $this->_endTable();
-
 
657
                    $this->_displayLine('');
-
 
658
                }
-
 
659
                $this->_displayLine($data['data']);
-
 
660
                break;
-
 
661
            case 'search':
-
 
662
                $this->_startTable($data);
-
 
663
                if (isset($data['headline']) && is_array($data['headline'])) {
-
 
664
                    $this->_tableRow($data['headline'], array('bold' => true), array(1 => array('wrap' => 55)));
-
 
665
                }
-
 
666
 
-
 
667
                foreach($data['data'] as $category) {
-
 
668
                    foreach($category as $pkg) {
-
 
669
                        $this->_tableRow($pkg, null, array(1 => array('wrap' => 55)));
-
 
670
                    }
-
 
671
                };
-
 
672
                $this->_endTable();
-
 
673
                break;
-
 
674
            case 'list-all':
-
 
675
                $this->_startTable($data);
-
 
676
                if (isset($data['headline']) && is_array($data['headline'])) {
-
 
677
                    $this->_tableRow($data['headline'], array('bold' => true), array(1 => array('wrap' => 55)));
-
 
678
                }
-
 
679
 
-
 
680
                foreach($data['data'] as $category) {
-
 
681
                    foreach($category as $pkg) {
-
 
682
                        unset($pkg[4]);
-
 
683
                        unset($pkg[5]);
-
 
684
                        $this->_tableRow($pkg, null, array(1 => array('wrap' => 55)));
-
 
685
                    }
-
 
686
                };
-
 
687
                $this->_endTable();
-
 
688
                break;
-
 
689
            case 'config-show':
-
 
690
                $data['border'] = false;
-
 
691
                $opts = array(0 => array('wrap' => 30),
-
 
692
                              1 => array('wrap' => 20),
-
 
693
                              2 => array('wrap' => 35));
-
 
694
                $this->_startTable($data);
-
 
695
                if (isset($data['headline']) && is_array($data['headline'])) {
-
 
696
                    $this->_tableRow($data['headline'],
-
 
697
                                     array('bold' => true),
-
 
698
                                     $opts);
-
 
699
                }
-
 
700
                foreach($data['data'] as $group) {
-
 
701
                    foreach($group as $value) {
-
 
702
                        if ($value[2] == '') {
-
 
703
                            $value[2] = "<not set>";
-
 
704
                        }
-
 
705
                        $this->_tableRow($value, null, $opts);
-
 
706
                    }
-
 
707
                }
-
 
708
                $this->_endTable();
-
 
709
                break;
-
 
710
            case 'remote-info':
-
 
711
                $d = $data;
-
 
712
                $data = array(
-
 
713
                    'caption' => 'Package details:',
-
 
714
                    'border' => false,
-
 
715
                    'data' => array(
-
 
716
                        array("Latest",    $data['stable']),
-
 
717
                        array("Installed", $data['installed']),
-
 
718
                        array("Package",   $data['name']),
-
 
719
                        array("License",   $data['license']),
-
 
720
                        array("Category",  $data['category']),
-
 
721
                        array("Summary",   $data['summary']),
-
 
722
                        array("Description", $data['description']),
-
 
723
                        ),
-
 
724
                    );
-
 
725
                    if (isset($d['deprecated']) && $d['deprecated']) {
-
 
726
                        $conf = &PEAR_Config::singleton();
-
 
727
                        $reg = $conf->getRegistry();
-
 
728
                        $name = $reg->parsedPackageNameToString($d['deprecated'], true);
-
 
729
                        $data['data'][] = array('Deprecated! use', $name);
-
 
730
                    }
-
 
731
            default: {
-
 
732
                if (is_array($data)) {
-
 
733
                    $this->_startTable($data);
-
 
734
                    $count = count($data['data'][0]);
-
 
735
                    if ($count == 2) {
-
 
736
                        $opts = array(0 => array('wrap' => 25),
-
 
737
                                      1 => array('wrap' => 48)
-
 
738
                        );
-
 
739
                    } elseif ($count == 3) {
-
 
740
                        $opts = array(0 => array('wrap' => 30),
-
 
741
                                      1 => array('wrap' => 20),
-
 
742
                                      2 => array('wrap' => 35)
-
 
743
                        );
-
 
744
                    } else {
-
 
745
                        $opts = null;
-
 
746
                    }
-
 
747
                    if (isset($data['headline']) && is_array($data['headline'])) {
-
 
748
                        $this->_tableRow($data['headline'],
-
 
749
                                         array('bold' => true),
-
 
750
                                         $opts);
-
 
751
                    }
-
 
752
                    foreach($data['data'] as $row) {
-
 
753
                        $this->_tableRow($row, null, $opts);
-
 
754
                    }
738
        }
755
                    $this->_endTable();
-
 
756
                } else {
-
 
757
                    $this->_displayLine($data);
-
 
758
                }
-
 
759
            }
-
 
760
        }
-
 
761
    }
-
 
762
 
-
 
763
    // }}}
-
 
764
    // {{{ log(text)
-
 
765
 
739
    }
766
 
-
 
767
    function log($text, $append_crlf = true)
-
 
768
    {
-
 
769
        if ($append_crlf) {
740
 
770
            return $this->_displayLine($text);
741
    function _displayLine($text)
Line 771... Line -...
771
        }
-
 
772
        return $this->_display($text);
-
 
773
    }
-
 
774
 
-
 
775
 
742
    {
776
    // }}}
743
        print "$this->lp$text\n";
777
    // {{{ bold($text)
-
 
778
 
744
    }
779
    function bold($text)
-
 
780
    {
-
 
781
        if (empty($this->term['bold'])) {
745
 
782
            return strtoupper($text);
-
 
783
        }
-
 
784
        return $this->term['bold'] . $text . $this->term['normal'];
746
    function _display($text)
785
    }
-
 
786
 
-