|
8 | 8 |
|
9 | 9 | namespace Inhere\Console\Concern; |
10 | 10 |
|
11 | | -use Closure; |
12 | | -use Generator; |
13 | | -use Inhere\Console\Component\Formatter\HelpPanel; |
14 | | -use Inhere\Console\Component\Formatter\MultiList; |
15 | | -use Inhere\Console\Component\Formatter\Panel; |
16 | | -use Inhere\Console\Component\Formatter\Section; |
17 | | -use Inhere\Console\Component\Formatter\SingleList; |
18 | | -use Inhere\Console\Component\Formatter\Table; |
19 | | -use Inhere\Console\Component\Formatter\Title; |
20 | | -use Toolkit\Cli\Style; |
21 | 11 | use Inhere\Console\Console; |
22 | | -use Inhere\Console\Util\Interact; |
23 | | -use Inhere\Console\Util\Show; |
24 | | -use LogicException; |
25 | 12 | use Toolkit\Stdlib\Php; |
26 | 13 | use function array_merge; |
27 | 14 | use function json_encode; |
28 | | -use function method_exists; |
29 | | -use function sprintf; |
30 | | -use function strpos; |
31 | | -use function substr; |
32 | 15 |
|
33 | 16 | /** |
34 | 17 | * Class FormatOutputAwareTrait |
35 | 18 | * |
36 | 19 | * @package Inhere\Console\Traits |
37 | | - * |
38 | | - * @method int info($messages, $quit = false) |
39 | | - * @method int note($messages, $quit = false) |
40 | | - * @method int notice($messages, $quit = false) |
41 | | - * @method int success($messages, $quit = false) |
42 | | - * @method int primary($messages, $quit = false) |
43 | | - * @method int warning($messages, $quit = false) |
44 | | - * @method int danger($messages, $quit = false) |
45 | | - * @method int error($messages, $quit = false) |
46 | | - * |
47 | | - * @method int liteInfo($messages, $quit = false) |
48 | | - * @method int liteNote($messages, $quit = false) |
49 | | - * @method int liteNotice($messages, $quit = false) |
50 | | - * @method int liteSuccess($messages, $quit = false) |
51 | | - * @method int litePrimary($messages, $quit = false) |
52 | | - * @method int liteWarning($messages, $quit = false) |
53 | | - * @method int liteDanger($messages, $quit = false) |
54 | | - * @method int liteError($messages, $quit = false) |
55 | | - * |
56 | | - * @method padding(array $data, string $title = null, array $opts = []) |
57 | | - * |
58 | | - * @method splitLine(string $title, string $char = '-', int $width = 0) |
59 | | - * @method spinner($msg = '', $ended = false) |
60 | | - * @method loading($msg = 'Loading ', $ended = false) |
61 | | - * @method pending($msg = 'Pending ', $ended = false) |
62 | | - * @method pointing($msg = 'handling ', $ended = false) |
63 | | - * |
64 | | - * @method Generator counterTxt($msg = 'Pending ', $ended = false) |
65 | | - * |
66 | | - * @method confirm(string $question, bool $default = true): bool |
67 | | - * @method unConfirm(string $question, bool $default = true): bool |
68 | | - * @method select(string $description, $options, $default = null, bool $allowExit = true): string |
69 | | - * @method checkbox(string $description, $options, $default = null, bool $allowExit = true): array |
70 | | - * @method ask(string $question, string $default = '', Closure $validator = null): string |
71 | | - * @method askPassword(string $prompt = 'Enter Password:'): string |
72 | 20 | */ |
73 | 21 | trait FormatOutputAwareTrait |
74 | 22 | { |
| 23 | + use StyledOutputAwareTrait; |
| 24 | + |
75 | 25 | /** |
76 | 26 | * @inheritdoc |
77 | 27 | * @see Console::write() |
@@ -139,175 +89,6 @@ public function writeRaw($text, bool $nl = true, $quit = false, array $opts = [] |
139 | 89 | return Console::writeRaw($text, $nl, $quit, $opts); |
140 | 90 | } |
141 | 91 |
|
142 | | - /** |
143 | | - * @param string $text |
144 | | - * @param string $tag |
145 | | - * |
146 | | - * @return int |
147 | | - */ |
148 | | - public function colored(string $text, string $tag = 'info'): int |
149 | | - { |
150 | | - return $this->writeln(sprintf('<%s>%s</%s>', $tag, $text, $tag)); |
151 | | - } |
152 | | - |
153 | | - /** |
154 | | - * @param array|mixed $messages |
155 | | - * @param string $type |
156 | | - * @param string $style |
157 | | - * @param bool $quit |
158 | | - * |
159 | | - * @return int |
160 | | - */ |
161 | | - public function block($messages, string $type = 'MESSAGE', string $style = Style::NORMAL, $quit = false): int |
162 | | - { |
163 | | - return Show::block($messages, $type, $style, $quit); |
164 | | - } |
165 | | - |
166 | | - /** |
167 | | - * @param array|mixed $messages |
168 | | - * @param string $type |
169 | | - * @param string $style |
170 | | - * @param bool $quit |
171 | | - * |
172 | | - * @return int |
173 | | - */ |
174 | | - public function liteBlock($messages, string $type = 'MESSAGE', string $style = Style::NORMAL, $quit = false): int |
175 | | - { |
176 | | - return Show::liteBlock($messages, $type, $style, $quit); |
177 | | - } |
178 | | - |
179 | | - /** |
180 | | - * @param string $title |
181 | | - * @param array $opts |
182 | | - */ |
183 | | - public function title(string $title, array $opts = []): void |
184 | | - { |
185 | | - Title::show($title, $opts); |
186 | | - } |
187 | | - |
188 | | - /** |
189 | | - * @param string $title |
190 | | - * @param string|array $body The section body message |
191 | | - * @param array $opts |
192 | | - */ |
193 | | - public function section(string $title, $body, array $opts = []): void |
194 | | - { |
195 | | - Section::show($title, $body, $opts); |
196 | | - } |
197 | | - |
198 | | - /** |
199 | | - * @param array|mixed $data |
200 | | - * @param string $title |
201 | | - * @param array $opts |
202 | | - */ |
203 | | - public function aList($data, string $title = 'Information', array $opts = []): void |
204 | | - { |
205 | | - SingleList::show($data, $title, $opts); |
206 | | - } |
207 | | - |
208 | | - /** |
209 | | - * @param array $data |
210 | | - * @param array $opts |
211 | | - */ |
212 | | - public function multiList(array $data, array $opts = []): void |
213 | | - { |
214 | | - MultiList::show($data, $opts); |
215 | | - } |
216 | | - |
217 | | - /** |
218 | | - * @param array $data |
219 | | - * @param array $opts |
220 | | - */ |
221 | | - public function mList(array $data, array $opts = []): void |
222 | | - { |
223 | | - MultiList::show($data, $opts); |
224 | | - } |
225 | | - |
226 | | - /** |
227 | | - * @param array $config |
228 | | - */ |
229 | | - public function helpPanel(array $config): void |
230 | | - { |
231 | | - HelpPanel::show($config); |
232 | | - } |
233 | | - |
234 | | - /** |
235 | | - * @param array $data |
236 | | - * @param string $title |
237 | | - * @param array $opts |
238 | | - */ |
239 | | - public function panel(array $data, string $title = 'Information panel', array $opts = []): void |
240 | | - { |
241 | | - Panel::show($data, $title, $opts); |
242 | | - } |
243 | | - |
244 | | - /** |
245 | | - * @param array $data |
246 | | - * @param string $title |
247 | | - * @param array $opts |
248 | | - */ |
249 | | - public function table(array $data, string $title = 'Data Table', array $opts = []): void |
250 | | - { |
251 | | - Table::show($data, $title, $opts); |
252 | | - } |
253 | | - |
254 | | - /** |
255 | | - * @param int $total |
256 | | - * @param string $msg |
257 | | - * @param string $doneMsg |
258 | | - * |
259 | | - * @return Generator |
260 | | - */ |
261 | | - public function progressTxt(int $total, string $msg, string $doneMsg = ''): Generator |
262 | | - { |
263 | | - return Show::progressTxt($total, $msg, $doneMsg); |
264 | | - } |
265 | | - |
266 | | - /** |
267 | | - * @inheritdoc |
268 | | - * @see Show::progressBar() |
269 | | - */ |
270 | | - public function progressBar($total, array $opts = []): Generator |
271 | | - { |
272 | | - return Show::progressBar($total, $opts); |
273 | | - } |
274 | | - |
275 | | - /** |
276 | | - * @param string $method |
277 | | - * @param array $args |
278 | | - * |
279 | | - * @return int |
280 | | - * @throws LogicException |
281 | | - */ |
282 | | - public function __call($method, array $args = []) |
283 | | - { |
284 | | - $map = Show::getBlockMethods(false); |
285 | | - |
286 | | - if (isset($map[$method])) { |
287 | | - $msg = $args[0]; |
288 | | - $quit = $args[1] ?? false; |
289 | | - $style = $map[$method]; |
290 | | - |
291 | | - if (0 === strpos($method, 'lite')) { |
292 | | - $type = substr($method, 4); |
293 | | - return Show::liteBlock($msg, $type === 'Primary' ? 'IMPORTANT' : $type, $style, $quit); |
294 | | - } |
295 | | - |
296 | | - return Show::block($msg, $style === 'primary' ? 'IMPORTANT' : $style, $style, $quit); |
297 | | - } |
298 | | - |
299 | | - if (method_exists(Show::class, $method)) { |
300 | | - return Show::$method(...$args); |
301 | | - } |
302 | | - |
303 | | - // interact methods |
304 | | - if (method_exists(Interact::class, $method)) { |
305 | | - return Interact::$method(...$args); |
306 | | - } |
307 | | - |
308 | | - throw new LogicException("Call a not exists method: $method of the " . static::class); |
309 | | - } |
310 | | - |
311 | 92 | /** |
312 | 93 | * @param mixed $data |
313 | 94 | * @param bool $echo |
|
0 commit comments