|
2 | 2 |
|
3 | 3 | namespace Inhere\Console\Examples\Controllers; |
4 | 4 |
|
5 | | -use Inhere\Console\Components\AnsiCode; |
| 5 | +use Inhere\Console\Components\Terminal; |
6 | 6 | use Inhere\Console\Components\ArtFont; |
7 | 7 | use Inhere\Console\Components\Download; |
8 | 8 | use Inhere\Console\Controller; |
9 | 9 | use Inhere\Console\IO\Input; |
10 | 10 | use Inhere\Console\Utils\Helper; |
11 | 11 | use Inhere\Console\Utils\Interact; |
| 12 | +use Inhere\Console\Utils\ProgressBar; |
12 | 13 | use Inhere\Console\Utils\Show; |
13 | 14 |
|
14 | 15 | /** |
@@ -157,23 +158,27 @@ public function spinnerCommand() |
157 | 158 | Show::spinner(); |
158 | 159 | usleep(100); |
159 | 160 | } |
| 161 | + |
| 162 | + Show::spinner('Done', true); |
160 | 163 | } |
161 | 164 |
|
162 | 165 | /** |
163 | 166 | * dynamic notice message show: pending |
164 | 167 | */ |
165 | 168 | public function pendingCommand() |
166 | 169 | { |
167 | | - $total = 5000; |
| 170 | + $total = 8000; |
168 | 171 |
|
169 | 172 | while ($total--) { |
170 | | - Show::spinner(); |
171 | | - usleep(100); |
| 173 | + Show::pending(); |
| 174 | + usleep(200); |
172 | 175 | } |
| 176 | + |
| 177 | + Show::pending('Done', true); |
173 | 178 | } |
174 | 179 |
|
175 | 180 | /** |
176 | | - * a progress bar example show |
| 181 | + * a progress bar example show, by Show::progressBar() |
177 | 182 | * @options |
178 | 183 | * --type the progress type, allow: bar,txt. <cyan>txt</cyan> |
179 | 184 | * --done-char the done show char. <info>=</info> |
@@ -212,6 +217,26 @@ public function progressCommand($input) |
212 | 217 | return 0; |
213 | 218 | } |
214 | 219 |
|
| 220 | + /** |
| 221 | + * a progress bar example show, by class ProgressBar |
| 222 | + * @throws \LogicException |
| 223 | + */ |
| 224 | + public function prgCommand() |
| 225 | + { |
| 226 | + $i = 0; |
| 227 | + $total = 120; |
| 228 | + $bar = new ProgressBar(); |
| 229 | + $bar->start(120); |
| 230 | + |
| 231 | + while ($i <= $total) { |
| 232 | + $bar->advance(); |
| 233 | + usleep(50000); |
| 234 | + $i++; |
| 235 | + } |
| 236 | + |
| 237 | + $bar->finish(); |
| 238 | + } |
| 239 | + |
215 | 240 | /** |
216 | 241 | * output format message: title |
217 | 242 | */ |
@@ -592,39 +617,36 @@ public function downCommand() |
592 | 617 | } |
593 | 618 |
|
594 | 619 | /** |
595 | | - * This is a demo for show cursor move on the screen |
| 620 | + * This is a demo for show cursor move on the Terminal screen |
596 | 621 | */ |
597 | 622 | public function cursorCommand() |
598 | 623 | { |
599 | 624 | $this->write('hello, this in ' . __METHOD__); |
600 | | - |
601 | | - // $this->output->panel($_SERVER, 'Server information', ''); |
602 | | - |
603 | 625 | $this->write('this is a message text.', false); |
604 | 626 |
|
605 | 627 | sleep(1); |
606 | | - AnsiCode::make()->cursor(AnsiCode::CURSOR_BACKWARD, 6); |
| 628 | + Terminal::make()->cursor(Terminal::CURSOR_BACKWARD, 6); |
607 | 629 |
|
608 | 630 | sleep(1); |
609 | | - AnsiCode::make()->cursor(AnsiCode::CURSOR_FORWARD, 3); |
| 631 | + Terminal::make()->cursor(Terminal::CURSOR_FORWARD, 3); |
610 | 632 |
|
611 | 633 | sleep(1); |
612 | | - AnsiCode::make()->cursor(AnsiCode::CURSOR_BACKWARD, 2); |
| 634 | + Terminal::make()->cursor(Terminal::CURSOR_BACKWARD, 2); |
613 | 635 |
|
614 | 636 | sleep(2); |
615 | 637 |
|
616 | | - AnsiCode::make()->screen(AnsiCode::CLEAR_LINE, 3); |
| 638 | + Terminal::make()->screen(Terminal::CLEAR_LINE, 3); |
617 | 639 |
|
618 | 640 | $this->write('after 2s scroll down 3 row.'); |
619 | 641 |
|
620 | 642 | sleep(2); |
621 | 643 |
|
622 | | - AnsiCode::make()->screen(AnsiCode::SCROLL_DOWN, 3); |
| 644 | + Terminal::make()->screen(Terminal::SCROLL_DOWN, 3); |
623 | 645 |
|
624 | 646 | $this->write('after 3s clear screen.'); |
625 | 647 |
|
626 | 648 | sleep(3); |
627 | 649 |
|
628 | | - AnsiCode::make()->screen(AnsiCode::CLEAR); |
| 650 | + Terminal::make()->screen(Terminal::CLEAR); |
629 | 651 | } |
630 | 652 | } |
0 commit comments