forked from wp-cli/php-cli-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.php
More file actions
111 lines (103 loc) · 4.51 KB
/
example.php
File metadata and controls
111 lines (103 loc) · 4.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<?php
if (php_sapi_name() != 'cli') {
die('Must run from command line');
}
error_reporting(E_ALL | E_STRICT);
ini_set('display_errors', 1);
ini_set('log_errors', 0);
ini_set('html_errors', 0);
require __DIR__ . '/vendor/autoload.php';
$menu = array(
'out_out' => 'cli\out Example',
'out_err' => 'cli\err Example',
'out_line' => 'cli\line Example',
'notify_dots' => 'cli\notify\Dots Example',
'notify_spinner' => 'cli\notify\Spinner Example',
'progress_bar' => 'cli\progress\Bar Example',
'table' => 'cli\Table Example',
'colors' => 'cli\Colors example',
'quit' => 'Quit',
);
$headers = array('First Name', 'Last Name', 'City', 'State');
$data = array(
array('Maryam', 'Elliott', 'Elizabeth City', 'SD'),
array('Jerry', 'Washington', 'Bessemer', 'ME'),
array('Allegra', 'Hopkins', 'Altoona', 'ME'),
array('Audrey', 'Oneil', 'Dalton', 'SK'),
array('Ruth', 'Mcpherson', 'San Francisco', 'ID'),
array('Odessa', 'Tate', 'Chattanooga', 'FL'),
array('Violet', 'Nielsen', 'Valdosta', 'AB'),
array('Summer', 'Rollins', 'Revere', 'SK'),
array('Mufutau', 'Bowers', 'Scottsbluff', 'WI'),
array('Grace', 'Rosario', 'Garden Grove', 'KY'),
array('Amanda', 'Berry', 'La Habra', 'AZ'),
array('Cassady', 'York', 'Fulton', 'BC'),
array('Heather', 'Terrell', 'Statesboro', 'SC'),
array('Dominic', 'Jimenez', 'West Valley City', 'ME'),
array('Rhonda', 'Potter', 'Racine', 'BC'),
array('Nathan', 'Velazquez', 'Cedarburg', 'BC'),
array('Richard', 'Fletcher', 'Corpus Christi', 'BC'),
array('Cheyenne', 'Rios', 'Broken Arrow', 'VA'),
array('Velma', 'Clemons', 'Helena', 'IL'),
array('Samuel', 'Berry', 'Lawrenceville', 'NU'),
array('Marcia', 'Swanson', 'Fontana', 'QC'),
array('Zachary', 'Silva', 'Port Washington', 'MB'),
array('Hilary', 'Chambers', 'Suffolk', 'HI'),
array('Idola', 'Carroll', 'West Sacramento', 'QC'),
array('Kirestin', 'Stephens', 'Fitchburg', 'AB'),
);
function test_notify(\cli\Notify $notify, $cycle = 1000000, $sleep = null) {
for ($i = 0; $i <= $cycle; $i++) {
$notify->tick();
if ($sleep) usleep($sleep);
}
$notify->finish();
}
while (true) {
$choice = \cli\menu($menu, null, 'Choose an example');
\cli\line();
switch ($choice) {
case 'quit':
break 2;
case 'out_out':
\cli\out(" \\cli\\out sends output to STDOUT\n");
\cli\out(" It does not automatically append a new line\n");
\cli\out(" It does accept any number of %s which are then %s to %s for formatting\n", 'arguments', 'passed', 'sprintf');
\cli\out(" Alternatively, {:a} can use an {:b} as the second argument.\n", array('a' => 'you', 'b' => 'array'));
break;
case 'out_err':
\cli\err(' \cli\err sends output to STDERR');
\cli\err(' It does automatically append a new line');
\cli\err(' It does accept any number of %s which are then %s to %s for formatting', 'arguments', 'passed', 'sprintf');
\cli\err(' Alternatively, {:a} can use an {:b} as the second argument.', array('a' => 'you', 'b' => 'array'));
break;
case 'out_line':
\cli\line(' \cli\line forwards to \cli\out for output');
\cli\line(' It does automatically append a new line');
\cli\line(' It does accept any number of %s which are then %s to %s for formatting', 'arguments', 'passed', 'sprintf');
\cli\line(' Alternatively, {:a} can use an {:b} as the second argument.', array('a' => 'you', 'b' => 'array'));
break;
case 'notify_dots':
test_notify(new \cli\notify\Dots(' \cli\notify\Dots cycles through a set number of dots'));
test_notify(new \cli\notify\Dots(' You can disable the delay if ticks take longer than a few milliseconds', 5, 0), 10, 100000);
\cli\line(' All progress meters and notifiers extend \cli\Notify which handles the interval above.');
break;
case 'notify_spinner':
test_notify(new \cli\notify\Spinner(' \cli\notify\Spinner cycles through a set of characters to emulate a spinner'));
break;
case 'progress_bar':
test_notify(new \cli\progress\Bar(' \cli\progress\Bar displays a progress bar', 1000000));
test_notify(new \cli\progress\Bar(' It sizes itself dynamically', 1000000));
break;
case 'table':
$table = new \cli\Table();
$table->setHeaders($headers);
$table->setRows($data);
$table->display();
break;
case 'colors':
\cli\line(' %C%5All output is run through %Y%6\cli\Colors::colorize%C%5 before display%n');
break;
}
\cli\line();
}