@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -require_once __DIR__ .'/../vendor/autoload.php'; |
|
2 | +require_once __DIR__.'/../vendor/autoload.php'; |
|
3 | 3 | use Kristuff\Mishell\Console; |
4 | 4 | |
5 | 5 | Console::clear(); |
@@ -18,26 +18,26 @@ discard block |
||
18 | 18 | |
19 | 19 | Console::log(); |
20 | 20 | Console::log(); |
21 | - Console::log(' '. Console::text(" _ ", 'black', 'white') . Console::text(" ____ _ _ _ ", 'magenta', 'white')); |
|
22 | - Console::log(' '. Console::text(" _ __ ___ (_) ", 'black', 'white') . Console::text(" / ___|| |__ ___| | | ", 'magenta', 'white')); |
|
23 | - Console::log(' '. Console::text(" | '_ ` _ \| | ", 'black', 'white') . Console::text(" \___ \| '_ \ / _ \ | | ", 'magenta', 'white')); |
|
24 | - Console::log(' '. Console::text(" | | | | | | | ", 'black', 'white') . Console::text(" ___) | | | | __/ | | ", 'magenta', 'white')); |
|
25 | - Console::log(' '. Console::text(" |_| |_| |_|_| ", 'black', 'white') . Console::text(" |____/|_| |_|\___|_|_| ", 'magenta', 'white')); |
|
26 | - Console::log(' '. Console::text(" ", 'black', 'white') . Console::text(" ", 'magenta', 'white')); |
|
27 | - Console::log(' '. Console::text(" ", 'black', 'white') . Console::text(" Version 1.0 ", 'black', 'white')); |
|
28 | - Console::log(' '. Console::text(" ", 'black', 'white') . Console::text(" © 2020 Kristuff ", 'black', 'white')); |
|
29 | - Console::log(' '. Console::text(" ", 'black', 'white') . Console::text(" ", 'magenta', 'white')); |
|
21 | + Console::log(' '.Console::text(" _ ", 'black', 'white').Console::text(" ____ _ _ _ ", 'magenta', 'white')); |
|
22 | + Console::log(' '.Console::text(" _ __ ___ (_) ", 'black', 'white').Console::text(" / ___|| |__ ___| | | ", 'magenta', 'white')); |
|
23 | + Console::log(' '.Console::text(" | '_ ` _ \| | ", 'black', 'white').Console::text(" \___ \| '_ \ / _ \ | | ", 'magenta', 'white')); |
|
24 | + Console::log(' '.Console::text(" | | | | | | | ", 'black', 'white').Console::text(" ___) | | | | __/ | | ", 'magenta', 'white')); |
|
25 | + Console::log(' '.Console::text(" |_| |_| |_|_| ", 'black', 'white').Console::text(" |____/|_| |_|\___|_|_| ", 'magenta', 'white')); |
|
26 | + Console::log(' '.Console::text(" ", 'black', 'white').Console::text(" ", 'magenta', 'white')); |
|
27 | + Console::log(' '.Console::text(" ", 'black', 'white').Console::text(" Version 1.0 ", 'black', 'white')); |
|
28 | + Console::log(' '.Console::text(" ", 'black', 'white').Console::text(" © 2020 Kristuff ", 'black', 'white')); |
|
29 | + Console::log(' '.Console::text(" ", 'black', 'white').Console::text(" ", 'magenta', 'white')); |
|
30 | 30 | Console::log(); |
31 | 31 | Console::log(); |
32 | 32 | |
33 | 33 | $pad = ' '; |
34 | 34 | |
35 | 35 | // fake progress message |
36 | - for ($i=0 ; $i<=100 ; $i++) { |
|
36 | + for ($i = 0; $i <= 100; $i++) { |
|
37 | 37 | |
38 | 38 | // Overwrite progress message. |
39 | 39 | Console::relog($pad.Console::text('Loading... [', 'white'). |
40 | - Console::text($i .'%', 'green'). |
|
40 | + Console::text($i.'%', 'green'). |
|
41 | 41 | Console::text('] completed', 'white')); |
42 | 42 | |
43 | 43 | // wait for a while, so we see the animation |
@@ -55,25 +55,25 @@ discard block |
||
55 | 55 | |
56 | 56 | |
57 | 57 | |
58 | - $index[1] = ['Styles', 'How to get available basic styles', 'demo.styles.php']; |
|
59 | - $index[2] = ['Colors', 'How to get available foreground colors', 'demo.colors.php']; |
|
60 | - $index[3] = ['Backgrounds', 'How to get available background colors', 'demo.bgcolors.php']; |
|
58 | + $index[1] = ['Styles', 'How to get available basic styles', 'demo.styles.php']; |
|
59 | + $index[2] = ['Colors', 'How to get available foreground colors', 'demo.colors.php']; |
|
60 | + $index[3] = ['Backgrounds', 'How to get available background colors', 'demo.bgcolors.php']; |
|
61 | 61 | |
62 | - $index[11] = ['Ask', 'How to ask? (get user input)', 'demo.ask.php']; |
|
63 | - $index[12] = ['Ask Number', 'How to ask and expect a number?', 'demo.askint.php']; |
|
64 | - $index[13] = ['Ask Password', 'How to ask a password? (do not print user input)', 'demo.askpassword.php']; |
|
62 | + $index[11] = ['Ask', 'How to ask? (get user input)', 'demo.ask.php']; |
|
63 | + $index[12] = ['Ask Number', 'How to ask and expect a number?', 'demo.askint.php']; |
|
64 | + $index[13] = ['Ask Password', 'How to ask a password? (do not print user input)', 'demo.askpassword.php']; |
|
65 | 65 | |
66 | - $index[14] = ['Table', 'How to print a table?', 'demo.table.php']; |
|
67 | - $index[15] = ['Bell', 'How to run the bell?', 'demo.bell.php']; |
|
68 | - $index[16] = ['Progress', 'How to output progress message?', 'demo.progress.php']; |
|
69 | - $index[17] = ['New window', 'How to open new/restore window?', 'demo.window.php']; |
|
66 | + $index[14] = ['Table', 'How to print a table?', 'demo.table.php']; |
|
67 | + $index[15] = ['Bell', 'How to run the bell?', 'demo.bell.php']; |
|
68 | + $index[16] = ['Progress', 'How to output progress message?', 'demo.progress.php']; |
|
69 | + $index[17] = ['New window', 'How to open new/restore window?', 'demo.window.php']; |
|
70 | 70 | |
71 | 71 | // $index[4] = ['Text', 'Console::text() overview', 'demo.log.php']; |
72 | 72 | // $index[5] = ['Log', 'Console::log() overview', 'demo.log.php']; |
73 | 73 | // $index[6] = ['ReLog', 'Console::relog() overview', 'demo.relog.php']; |
74 | - $index[7] = ['Pad', 'Console::pad() overview', 'demo.pad.php']; |
|
75 | - $index[8] = ['Size', 'How to get the number of columns and lines in terminal', 'demo.size.php']; |
|
76 | - $index[9] = ['BlueScreen', 'Really nice full screen centered message sample', 'demo.bluescreen.php']; |
|
74 | + $index[7] = ['Pad', 'Console::pad() overview', 'demo.pad.php']; |
|
75 | + $index[8] = ['Size', 'How to get the number of columns and lines in terminal', 'demo.size.php']; |
|
76 | + $index[9] = ['BlueScreen', 'Really nice full screen centered message sample', 'demo.bluescreen.php']; |
|
77 | 77 | |
78 | 78 | return $index; |
79 | 79 | } |
@@ -91,16 +91,16 @@ discard block |
||
91 | 91 | |
92 | 92 | function writeSampleHeader($index, $title) |
93 | 93 | { |
94 | - Console::log(' ' . Console::text(Console::pad('', 20, ' ', STR_PAD_BOTH), 'white', 'bold', 'underline')); |
|
95 | - Console::log(' ' . Console::text(Console::pad('', 20, ' ', STR_PAD_BOTH), 'white', 'yellow', 'bold')); |
|
96 | - Console::log(' ' . Console::text(Console::pad($index .' - ' . $title, 20, ' ', STR_PAD_BOTH), 'white', 'yellow', 'bold')); |
|
97 | - Console::log(' ' . Console::text(Console::pad('', 20, ' ', STR_PAD_BOTH), 'white', 'yellow', 'bold', 'underline')); |
|
94 | + Console::log(' '.Console::text(Console::pad('', 20, ' ', STR_PAD_BOTH), 'white', 'bold', 'underline')); |
|
95 | + Console::log(' '.Console::text(Console::pad('', 20, ' ', STR_PAD_BOTH), 'white', 'yellow', 'bold')); |
|
96 | + Console::log(' '.Console::text(Console::pad($index.' - '.$title, 20, ' ', STR_PAD_BOTH), 'white', 'yellow', 'bold')); |
|
97 | + Console::log(' '.Console::text(Console::pad('', 20, ' ', STR_PAD_BOTH), 'white', 'yellow', 'bold', 'underline')); |
|
98 | 98 | Console::log(); |
99 | 99 | } |
100 | 100 | |
101 | 101 | function writeIndex() |
102 | 102 | { |
103 | - Console::log(' '. Console::text('Index:', 'underline', 'bold')); |
|
103 | + Console::log(' '.Console::text('Index:', 'underline', 'bold')); |
|
104 | 104 | $rowHeaders = ['Index' => 10, 'Item' => 25, 'Description' => 70]; |
105 | 105 | |
106 | 106 | // customize table separator |
@@ -125,18 +125,18 @@ discard block |
||
125 | 125 | Console::log(' '.Console::tableRowEmpty($rowHeaders, 'white', 'cyan')); |
126 | 126 | |
127 | 127 | $i = 0; |
128 | - foreach (getIndex() as $key => $value){ |
|
128 | + foreach (getIndex() as $key => $value) { |
|
129 | 129 | |
130 | - if (file_exists( __DIR__ . '/'. $value[2])) { |
|
130 | + if (file_exists(__DIR__.'/'.$value[2])) { |
|
131 | 131 | Console::log(' '. |
132 | 132 | Console::tableRow([ |
133 | 133 | $key => 10, |
134 | 134 | $value[0] => 25, |
135 | 135 | $value[1] => 70 |
136 | 136 | ], |
137 | - ($i % 2 == 1) ? 'white' : 'white', |
|
138 | - ($i % 2 == 1) ? 'cyan' : 'cyan', |
|
139 | - ($i % 2 == 1) ? '' : 'bold' |
|
137 | + ($i%2 == 1) ? 'white' : 'white', |
|
138 | + ($i%2 == 1) ? 'cyan' : 'cyan', |
|
139 | + ($i%2 == 1) ? '' : 'bold' |
|
140 | 140 | ) |
141 | 141 | ); |
142 | 142 | $i++; |
@@ -151,19 +151,19 @@ discard block |
||
151 | 151 | // -------------------- |
152 | 152 | |
153 | 153 | Console::log(''); |
154 | - Console::log(' ' .Console::text('Tips:', 'underline', 'bold')); |
|
155 | - Console::log(' '. Console::text('- At any time you can stop this program using [', 'green') .Console::text('Ctrl+C', 'black','white') .Console::text(']', 'green')); |
|
154 | + Console::log(' '.Console::text('Tips:', 'underline', 'bold')); |
|
155 | + Console::log(' '.Console::text('- At any time you can stop this program using [', 'green').Console::text('Ctrl+C', 'black', 'white').Console::text(']', 'green')); |
|
156 | 156 | Console::log(''); |
157 | 157 | } |
158 | 158 | |
159 | 159 | function askIndex() |
160 | 160 | { |
161 | - $base = Console::text('~miShell^^' , 'yellow'); |
|
162 | - $base .= Console::text(' $ ' , 'gray'); |
|
163 | - $selectedIndex = Console::askInt($base . Console::text('Enter desired index then press [Enter] to run sample > ', 'white')); |
|
161 | + $base = Console::text('~miShell^^', 'yellow'); |
|
162 | + $base .= Console::text(' $ ', 'gray'); |
|
163 | + $selectedIndex = Console::askInt($base.Console::text('Enter desired index then press [Enter] to run sample > ', 'white')); |
|
164 | 164 | $index = getIndex(); |
165 | 165 | |
166 | - switch($selectedIndex){ |
|
166 | + switch ($selectedIndex) { |
|
167 | 167 | case 0: |
168 | 168 | Console::log(); |
169 | 169 | exit(); |
@@ -174,39 +174,39 @@ discard block |
||
174 | 174 | |
175 | 175 | $title = $index[$selectedIndex][0]; |
176 | 176 | $fileName = $index[$selectedIndex][2]; |
177 | - $filePath = __DIR__ . '/'. $fileName; |
|
177 | + $filePath = __DIR__.'/'.$fileName; |
|
178 | 178 | |
179 | 179 | Console::clear(); |
180 | 180 | writeHeader(); |
181 | 181 | writeSampleHeader($selectedIndex, $title); |
182 | 182 | |
183 | - Console::log($base . Console::text('Start running [', 'white') . |
|
184 | - Console::text( $title, 'lightcyan') . |
|
185 | - Console::text('] in file [', 'white') . |
|
186 | - Console::text( $fileName, 'lightcyan') . |
|
183 | + Console::log($base.Console::text('Start running [', 'white'). |
|
184 | + Console::text($title, 'lightcyan'). |
|
185 | + Console::text('] in file [', 'white'). |
|
186 | + Console::text($fileName, 'lightcyan'). |
|
187 | 187 | Console::text(']', 'white')); |
188 | 188 | |
189 | - if (file_exists($filePath)){ |
|
189 | + if (file_exists($filePath)) { |
|
190 | 190 | Console::log(); |
191 | 191 | include $filePath; |
192 | 192 | Console::log(); |
193 | - Console::log($base . Console::text('End running [', 'white') . |
|
194 | - Console::text( $title, 'lightcyan') . |
|
193 | + Console::log($base.Console::text('End running [', 'white'). |
|
194 | + Console::text($title, 'lightcyan'). |
|
195 | 195 | Console::text(']', 'white')); |
196 | - $response = Console::ask($base . Console::text('Do you want to see the code that has been executed? (type y/Y to see the code) > ', 'white')); |
|
196 | + $response = Console::ask($base.Console::text('Do you want to see the code that has been executed? (type y/Y to see the code) > ', 'white')); |
|
197 | 197 | if (strtoupper($response) === 'Y') { |
198 | - Console::log($base . Console::text('The code in file [', 'white') . |
|
199 | - Console::text( $fileName, 'lightcyan') . |
|
198 | + Console::log($base.Console::text('The code in file [', 'white'). |
|
199 | + Console::text($fileName, 'lightcyan'). |
|
200 | 200 | Console::text('] is:', 'white')); |
201 | 201 | Console::log(); |
202 | 202 | |
203 | 203 | $lines = file($filePath, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); |
204 | 204 | $count = 1; |
205 | - foreach($lines as $line){ |
|
205 | + foreach ($lines as $line) { |
|
206 | 206 | $codeLine = rtrim($line); |
207 | 207 | $isComment = substr(ltrim($codeLine), 0, 2) === '//'; |
208 | 208 | Console::log( |
209 | - Console::pad($count . ' ', 3, ' ', STR_PAD_LEFT) . |
|
209 | + Console::pad($count.' ', 3, ' ', STR_PAD_LEFT). |
|
210 | 210 | Console::text(Console::pad($codeLine, 150), $isComment ? 'magenta' : 'black', 'white') |
211 | 211 | ); |
212 | 212 | $count++; |
@@ -214,17 +214,17 @@ discard block |
||
214 | 214 | Console::log(); |
215 | 215 | } |
216 | 216 | } else { |
217 | - Console::log($base . Console::text('Error' , 'red')); |
|
218 | - Console::log($base . Console::text(' => File missing [' . $fileName . ']' , 'red')); |
|
217 | + Console::log($base.Console::text('Error', 'red')); |
|
218 | + Console::log($base.Console::text(' => File missing ['.$fileName.']', 'red')); |
|
219 | 219 | } |
220 | 220 | |
221 | 221 | } else { |
222 | - Console::log($base . Console::text('Error:', 'red')); |
|
223 | - Console::log($base . Console::text('=> the value you entered is not a valid index number.', 'red')); |
|
222 | + Console::log($base.Console::text('Error:', 'red')); |
|
223 | + Console::log($base.Console::text('=> the value you entered is not a valid index number.', 'red')); |
|
224 | 224 | askIndex(); |
225 | 225 | } |
226 | 226 | |
227 | - Console::ask($base . Console::text('Press [Enter] to go back to index > ', 'white')); |
|
227 | + Console::ask($base.Console::text('Press [Enter] to go back to index > ', 'white')); |
|
228 | 228 | goIndex(); |
229 | 229 | } |
230 | 230 | } |
231 | 231 | \ No newline at end of file |