1 | <?php |
||
2 | require_once __DIR__ .'/../vendor/autoload.php'; |
||
3 | use Kristuff\Mishell\Console; |
||
4 | |||
5 | |||
6 | Console::log(' '. Console::text('Overview:', 'underlined', 'bold')); |
||
7 | Console::log(' '. Console::text('- Using ','white').Console::text("Console::overwrite()", 'lightblue', 'underlined').Console::text('you can overwrite more than one row.', 'white')); |
||
8 | Console::log(' '. Console::text('To overwrite the 2 last printed rows, you need to pass an array of 2 ','white').Console::text("string", 'lightblue', '').' '. Console::text('.', 'white')); |
||
9 | Console::log(); |
||
10 | |||
11 | Console::log(' '. Console::text('Tips:', 'underlined', 'bold')); |
||
12 | Console::log(" - " . Console::text('No need', 'underlined', 'bold') ." to use " . Console::text("php str_pad()", 'lightblue', 'underlined') . " method like with " .Console::text("Console::relog()", 'lightblue', 'underlined') ); |
||
13 | Console::log(" - You can customize colors (foreground and background) and some styles in same way than "); |
||
14 | Console::log(' ' .Console::text("Console::text()", 'lightblue', 'underlined') . |
||
15 | ' and ' . Console::text("Console::log()", 'lightblue', 'underlined'). ' methods.'); |
||
16 | Console::log(); |
||
17 | Console::log(' '. Console::text('Basic usage:', 'underlined', 'bold')); |
||
18 | Console::log(); |
||
19 | Console::log(" Console::log('I am a real log line, with \\n, but I will be erased');"); |
||
20 | Console::log(" Console::log('I am another real log line, with \\n, but I will be erased');"); |
||
21 | Console::log(" Console::overwrite('I am new real line.');"); |
||
22 | Console::log(); |
||
23 | Console::log(' ' .Console::text('Sample code:', 'underlined', 'bold')); |
||
24 | Console::log(); |
||
25 | // ----------------- |
||
26 | // sample start here |
||
27 | // ----------------- |
||
28 | |||
29 | $msg1 = Console::text(' [*]', 'blue'). Console::text(' Tortoise vs Hare Race will starting. Place your bets! ...', 'white'); |
||
30 | $msg2 = Console::text(' [*]', 'blue').Console::text(' 🐢 ', 'lightgreen').Console::text('Tortoise progress ... ', 'white'); |
||
31 | $msg3 = Console::text(' [*]', 'blue').Console::text(' 🐇 ', 'white').Console::text('Hare progress ... ', 'white'); |
||
32 | |||
33 | Console::log($msg1); |
||
34 | Console::log(); |
||
35 | Console::log($msg2); |
||
36 | Console::log(); |
||
37 | Console::log($msg3); |
||
38 | Console::log(); |
||
39 | |||
40 | // wait for a momment, so we see the animation |
||
41 | sleep(3); |
||
42 | |||
43 | $harePurcent = 0; |
||
44 | $tortPurcent = 0; |
||
45 | $hareColor = 'green'; |
||
46 | $tortoiseColor = 'red'; |
||
47 | $totalLines = Console::getLines(); |
||
48 | |||
49 | for ($i=1 ; $i<=100 ; $i++) { |
||
50 | |||
51 | // Added by Tortoise1337 |
||
52 | // Optimization seems legit |
||
53 | $isOdd = ($i % 2 == 0); |
||
54 | if ($i < 75 ){ |
||
55 | $isOdd && $tortPurcent++; |
||
56 | } else { |
||
57 | $tortPurcent = min($tortPurcent + 3, 100); |
||
58 | } |
||
59 | |||
60 | $harePurcent++; |
||
61 | $loserColor = ($i== 100) ? 'red' : 'yellow'; |
||
62 | $tortColor = $tortPurcent >= $harePurcent ? 'green' : $loserColor; |
||
63 | $hareColor = $tortPurcent < $harePurcent ? 'green' : $loserColor; |
||
64 | $msg1 = $i==100 ? |
||
65 | Console::text(' [*]', 'blue').Console::text(' Tortoise vs Hare Race - Final Results', 'white') : |
||
66 | Console::text(' [*]', 'blue').Console::text(' Tortoise vs Hare Race: ', 'white').Console::text(' RUNNING ', 'white', 'yellow'). ' ' ; |
||
67 | $msg2 = Console::text(' [*]', $i==100 ? $tortColor : 'blue').Console::text(' 🐢 ', 'lightgreen').Console::text('Tortoise progress: ', 'white').Console::progressBar($tortPurcent, $tortColor, $tortColor,'darkgray', 60, ' '); |
||
68 | $msg3 = Console::text(' [*]', $i==100 ? $hareColor : 'blue').Console::text(' 🐇 ', 'white'). Console::text('Hare progress: ', 'white').Console::progressBar($harePurcent, $hareColor, $hareColor,'darkgray', 60, ' '); |
||
69 | $msg2End = $tortPurcent == 100 ? Console::text(' 🏆 WINNER!!!', 'green') : ''; |
||
70 | |||
71 | Console::overwrite([$msg1,' ', $msg2.$msg2End,' ', $msg3, ' ']); |
||
72 | |||
73 | // wait a moment, so we see the animation |
||
74 | usleep(90000); |
||
75 | } |
||
76 | |||
77 | |||
78 | |||
79 | |||
80 | |||
81 | ?> |
||
0 ignored issues
–
show
|
|||
82 |
Using a closing tag in PHP files that only contain PHP code is not recommended as you might accidentally add whitespace after the closing tag which would then be output by PHP. This can cause severe problems, for example headers cannot be sent anymore.
A simple precaution is to leave off the closing tag as it is not required, and it also has no negative effects whatsoever.