Console::json()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 1
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/**
3
 * Webino™ (http://webino.sk)
4
 *
5
 * @link        https://github.com/webino for the canonical source repository
6
 * @copyright   Copyright (c) 2015-2017 Webino, s.r.o. (http://webino.sk)
7
 * @author      Peter Bačinský <[email protected]>
8
 * @license     BSD-3-Clause
9
 */
10
11
namespace WebinoAppLib\Service;
12
13
use League\CLImate\CLImate;
14
use League\CLImate\TerminalObject\Dynamic;
15
16
/**
17
 * Class Console
18
 */
19
class Console
20
{
21
    /**
22
     * @var CLImate
23
     */
24
    protected $engine;
25
26
    /**
27
     * @param CLImate $engine
28
     */
29
    public function __construct(CLImate $engine)
30
    {
31
        $this->engine = $engine;
32
    }
33
34
    /**
35
     * Add literal art directory
36
     *
37
     * @param string $dir
38
     * @return $this
39
     */
40
    public function addArt($dir)
41
    {
42
        $this->engine->addArt($dir);
43
        return $this;
44
    }
45
46
    /**
47
     * Clear screen
48
     *
49
     * @return $this
50
     */
51
    public function clear()
52
    {
53
        $this->engine->clear();
54
        return $this;
55
    }
56
57
    /**
58
     * Black text color
59
     *
60
     * @param string|null $str
61
     * @return $this
62
     */
63
    public function black($str = null)
64
    {
65
        $this->engine->black($str);
66
        return $this;
67
    }
68
69
    /**
70
     * Red text color
71
     *
72
     * @param string|null $str
73
     * @return $this
74
     */
75
    public function red($str = null)
76
    {
77
        $this->engine->red($str);
78
        return $this;
79
    }
80
81
    /**
82
     * Green text color
83
     *
84
     * @param string|null $str
85
     * @return $this
86
     */
87
    public function green($str = null)
88
    {
89
        $this->engine->green($str);
90
        return $this;
91
    }
92
93
    /**
94
     * Yellow text color
95
     *
96
     * @param string|null $str
97
     * @return $this
98
     */
99
    public function yellow($str = null)
100
    {
101
        $this->engine->yellow($str);
102
        return $this;
103
    }
104
105
    /**
106
     * Blue text color
107
     *
108
     * @param string|null $str
109
     * @return $this
110
     */
111
    public function blue($str = null)
112
    {
113
        $this->engine->blue($str);
114
        return $this;
115
    }
116
117
    /**
118
     * Magenta text color
119
     *
120
     * @param string|null $str
121
     * @return $this
122
     */
123
    public function magenta($str = null)
124
    {
125
        $this->engine->magenta($str);
126
        return $this;
127
    }
128
129
    /**
130
     * Cyan text color
131
     *
132
     * @param string|null $str
133
     * @return $this
134
     */
135
    public function cyan($str = null)
136
    {
137
        $this->engine->cyan($str);
138
        return $this;
139
    }
140
141
    /**
142
     * Light gray text color
143
     *
144
     * @param string|null $str
145
     * @return $this
146
     */
147
    public function lightGray($str = null)
148
    {
149
        $this->engine->lightGray($str);
150
        return $this;
151
    }
152
153
    /**
154
     * Dark gray text color
155
     *
156
     * @param string|null $str
157
     * @return $this
158
     */
159
    public function darkGray($str = null)
160
    {
161
        $this->engine->darkGray($str);
162
        return $this;
163
    }
164
165
    /**
166
     * Light red text color
167
     *
168
     * @param string|null $str
169
     * @return $this
170
     */
171
    public function lightRed($str = null)
172
    {
173
        $this->engine->lightRed($str);
174
        return $this;
175
    }
176
177
    /**
178
     * Light green text color
179
     *
180
     * @param string|null $str
181
     * @return $this
182
     */
183
    public function lightGreen($str = null)
184
    {
185
        $this->engine->lightGreen($str);
186
        return $this;
187
    }
188
189
    /**
190
     * Light yellow text color
191
     *
192
     * @param string|null $str
193
     * @return $this
194
     */
195
    public function lightYellow($str = null)
196
    {
197
        $this->engine->lightYellow($str);
198
        return $this;
199
    }
200
201
    /**
202
     * Light blue text color
203
     *
204
     * @param string|null $str
205
     * @return $this
206
     */
207
    public function lightBlue($str = null)
208
    {
209
        $this->engine->lightBlue($str);
210
        return $this;
211
    }
212
213
    /**
214
     * Light magenta text color
215
     *
216
     * @param string|null $str
217
     * @return $this
218
     */
219
    public function lightMagenta($str = null)
220
    {
221
        $this->engine->lightMagenta($str);
222
        return $this;
223
    }
224
225
    /**
226
     * Light cyan text color
227
     *
228
     * @param string|null $str
229
     * @return $this
230
     */
231
    public function lightCyan($str = null)
232
    {
233
        $this->engine->lightCyan($str);
234
        return $this;
235
    }
236
237
    /**
238
     * White text color
239
     *
240
     * @param string|null $str
241
     * @return $this
242
     */
243
    public function white($str = null)
244
    {
245
        $this->engine->white($str);
246
        return $this;
247
    }
248
249
    /**
250
     * Black background color
251
     *
252
     * @param string|null $str
253
     * @return $this
254
     */
255
    public function blackBg($str = null)
256
    {
257
        $this->engine->backgroundBlack($str);
258
        return $this;
259
    }
260
261
    /**
262
     * Red background color
263
     *
264
     * @param string|null $str
265
     * @return $this
266
     */
267
    public function redBg($str = null)
268
    {
269
        $this->engine->backgroundRed($str);
270
        return $this;
271
    }
272
273
    /**
274
     * Green background color
275
     *
276
     * @param string|null $str
277
     * @return $this
278
     */
279
    public function greenBg($str = null)
280
    {
281
        $this->engine->backgroundGreen($str);
282
        return $this;
283
    }
284
285
    /**
286
     * Yellow background color
287
     *
288
     * @param string|null $str
289
     * @return $this
290
     */
291
    public function yellowBg($str = null)
292
    {
293
        $this->engine->backgroundYellow($str);
294
        return $this;
295
    }
296
297
    /**
298
     * Blue background color
299
     *
300
     * @param string|null $str
301
     * @return $this
302
     */
303
    public function blueBg($str = null)
304
    {
305
        $this->engine->backgroundBlue($str);
306
        return $this;
307
    }
308
309
    /**
310
     * Magenta background color
311
     *
312
     * @param string|null $str
313
     * @return $this
314
     */
315
    public function magentaBg($str = null)
316
    {
317
        $this->engine->backgroundMagenta($str);
318
        return $this;
319
    }
320
321
    /**
322
     * Cyan background color
323
     *
324
     * @param string|null $str
325
     * @return $this
326
     */
327
    public function cyanBg($str = null)
328
    {
329
        $this->engine->backgroundCyan($str);
330
        return $this;
331
    }
332
333
    /**
334
     * Light gray background color
335
     *
336
     * @param string|null $str
337
     * @return $this
338
     */
339
    public function lightGrayBg($str = null)
340
    {
341
        $this->engine->backgroundLightGray($str);
342
        return $this;
343
    }
344
345
    /**
346
     * Dark gray background color
347
     *
348
     * @param string|null $str
349
     * @return $this
350
     */
351
    public function darkGrayBg($str = null)
352
    {
353
        $this->engine->backgroundDarkGray($str);
354
        return $this;
355
    }
356
357
    /**
358
     * Light red background color
359
     *
360
     * @param string|null $str
361
     * @return $this
362
     */
363
    public function lightRedBg($str = null)
364
    {
365
        $this->engine->backgroundLightRed($str);
366
        return $this;
367
    }
368
369
    /**
370
     * Light green background color
371
     *
372
     * @param string|null $str
373
     * @return $this
374
     */
375
    public function lightGreenBg($str = null)
376
    {
377
        $this->engine->backgroundLightGreen($str);
378
        return $this;
379
    }
380
381
    /**
382
     * Light yellow background color
383
     *
384
     * @param string|null $str
385
     * @return $this
386
     */
387
    public function lightYellowBg($str = null)
388
    {
389
        $this->engine->backgroundLightYellow($str);
390
        return $this;
391
    }
392
393
    /**
394
     * Light blue background color
395
     *
396
     * @param string|null $str
397
     * @return $this
398
     */
399
    public function lightBlueBg($str = null)
400
    {
401
        $this->engine->backgroundLightBlue($str);
402
        return $this;
403
    }
404
405
    /**
406
     * Light magenta background color
407
     *
408
     * @param string|null $str
409
     * @return $this
410
     */
411
    public function lightMagentaBg($str = null)
412
    {
413
        $this->engine->backgroundLightMagenta($str);
414
        return $this;
415
    }
416
417
    /**
418
     * Light cyan background color
419
     *
420
     * @param string|null $str
421
     * @return $this
422
     */
423
    public function lightCyanBg($str = null)
424
    {
425
        $this->engine->backgroundLightCyan($str);
426
        return $this;
427
    }
428
429
    /**
430
     * White background color
431
     *
432
     * @param string|null $str
433
     * @return $this
434
     */
435
    public function whiteBg($str = null)
436
    {
437
        $this->engine->backgroundWhite($str);
438
        return $this;
439
    }
440
441
    /**
442
     * Bold text
443
     *
444
     * @param string|null $str
445
     * @return $this
446
     */
447
    public function bold($str = null)
448
    {
449
        $this->engine->bold($str);
450
        return $this;
451
    }
452
453
    /**
454
     * Dimmed text
455
     *
456
     * @param string|null $str
457
     * @return $this
458
     */
459
    public function dim($str = null)
460
    {
461
        $this->engine->dim($str);
462
        return $this;
463
    }
464
465
    /**
466
     * Underlined text
467
     *
468
     * @param string|null $str
469
     * @return $this
470
     */
471
    public function underline($str = null)
472
    {
473
        $this->engine->underline($str);
474
        return $this;
475
    }
476
477
    /**
478
     * Inverted text
479
     *
480
     * @param string|null $str
481
     * @return $this
482
     */
483
    public function invert($str = null)
484
    {
485
        $this->engine->invert($str);
486
        return $this;
487
    }
488
489
    /**
490
     * Info text
491
     *
492
     * @param string|null $str
493
     * @return $this
494
     */
495
    public function info($str = null)
496
    {
497
        $this->engine->info($str);
498
        return $this;
499
    }
500
501
    /**
502
     * Comment text
503
     *
504
     * @param string|null $str
505
     * @return $this
506
     */
507
    public function comment($str = null)
508
    {
509
        $this->engine->comment($str);
510
        return $this;
511
    }
512
513
    /**
514
     * Whispered text
515
     *
516
     * @param string|null $str
517
     * @return $this
518
     */
519
    public function whisper($str = null)
520
    {
521
        $this->engine->whisper($str);
522
        return $this;
523
    }
524
525
    /**
526
     * Shouted text
527
     *
528
     * @param string|null $str
529
     * @return $this
530
     */
531
    public function shout($str = null)
532
    {
533
        $this->engine->shout($str);
534
        return $this;
535
    }
536
537
    /**
538
     * Error text
539
     *
540
     * @param string|null $str
541
     * @return $this
542
     */
543
    public function error($str = null)
544
    {
545
        $this->engine->error($str);
546
        return $this;
547
    }
548
549
    /**
550
     * Data columns
551
     *
552
     * @param array $data
553
     * @param int|null $columnCount
554
     * @return $this
555
     */
556
    public function columns(array $data, $columnCount = null)
557
    {
558
        $this->engine->columns($data, $columnCount);
559
        return $this;
560
    }
561
562
    /**
563
     * Text output
564
     *
565
     * @param string $str
566
     * @return $this
567
     */
568
    public function out($str)
569
    {
570
        $this->engine->out($str);
571
        return $this;
572
    }
573
574
    /**
575
     * Inline text output
576
     *
577
     * @param string $str
578
     * @return $this
579
     */
580
    public function inline($str)
581
    {
582
        $this->engine->inline($str);
583
        return $this;
584
    }
585
586
    /**
587
     * Data table
588
     *
589
     * @param array $data
590
     * @return $this
591
     */
592
    public function table(array $data)
593
    {
594
        $this->engine->table($data);
595
        return $this;
596
    }
597
598
    /**
599
     * JSON data
600
     *
601
     * @param mixed $var
602
     * @return $this
603
     */
604
    public function json($var)
605
    {
606
        $this->engine->json($var);
607
        return $this;
608
    }
609
610
    /**
611
     * Space
612
     *
613
     * @param int $count
614
     * @return $this
615
     */
616
    public function sp($count = 1)
617
    {
618
        for ($i=0; $i < $count; $i++) {
619
            $this->engine->inline(' ');
620
        }
621
        return $this;
622
    }
623
624
    /**
625
     * New line
626
     *
627
     * @param int $count
628
     * @return $this
629
     */
630
    public function br($count = 1)
631
    {
632
        $this->engine->br($count);
633
        return $this;
634
    }
635
636
    /**
637
     * Tabulator
638
     *
639
     * @param int $count
640
     * @return $this
641
     */
642
    public function tab($count = 1)
643
    {
644
        $this->engine->tab($count);
645
        return $this;
646
    }
647
648
    /**
649
     * Draw art
650
     *
651
     * @param string $art
652
     * @return $this
653
     */
654
    public function draw($art)
655
    {
656
        $this->engine->draw($art);
657
        return $this;
658
    }
659
660
    /**
661
     * Literal border
662
     *
663
     * @param string|null $char
664
     * @param int|null $length
665
     * @return $this
666
     */
667
    public function border($char = null, $length = null)
668
    {
669
        $this->engine->border($char, $length);
670
        return $this;
671
    }
672
673
    /**
674
     * Variable debug
675
     *
676
     * @param mixed $var
677
     * @return $this
678
     */
679
    public function dump($var)
680
    {
681
        $this->engine->dump($var);
682
        return $this;
683
    }
684
685
    /**
686
     * Literal strong text
687
     *
688
     * @param string $output
689
     * @param string|null $char
690
     * @param int|null $length
691
     * @return $this
692
     */
693
    public function flank($output, $char = null, $length = null)
694
    {
695
        $this->engine->flank($output, $char, $length);
696
        return $this;
697
    }
698
699
    /**
700
     * Progress bar
701
     *
702
     * @param int|null $total
703
     * @return Dynamic\Progress
704
     */
705
    public function progress($total = null)
706
    {
707
        return $this->engine->progress($total);
708
    }
709
710
    /**
711
     * Left literal padding
712
     *
713
     * @param int $length
714
     * @param string $char
715
     * @return Dynamic\Padding
716
     */
717
    public function padding($length = 0, $char = '.')
718
    {
719
        return $this->engine->padding($length, $char);
720
    }
721
722
    /**
723
     * Optional input text
724
     *
725
     * @param string $prompt
726
     * @return Dynamic\Input
727
     */
728
    public function input($prompt)
729
    {
730
        return $this->engine->input($prompt);
731
    }
732
733
    /**
734
     * Confirmation input text
735
     *
736
     * @param string $prompt
737
     * @return Dynamic\Confirm
738
     */
739
    public function confirm($prompt)
740
    {
741
        return $this->engine->confirm($prompt);
742
    }
743
744
    /**
745
     * Password input text
746
     *
747
     * @param string $prompt
748
     * @return Dynamic\Password
749
     */
750
    public function password($prompt)
751
    {
752
        return $this->engine->password($prompt);
753
    }
754
755
    /**
756
     * Multi-option input text
757
     *
758
     * @param string $prompt
759
     * @param array $options
760
     * @return Dynamic\Checkboxes
761
     */
762
    public function checkboxes($prompt, array $options)
763
    {
764
        return $this->engine->checkboxes($prompt, $options);
765
    }
766
767
    /**
768
     * Single-option input text
769
     *
770
     * @param string $prompt
771
     * @param array $options
772
     * @return Dynamic\Radio
773
     */
774
    public function radio($prompt, array $options)
775
    {
776
        return $this->engine->radio($prompt, $options);
777
    }
778
779
    /**
780
     * Play an animation
781
     *
782
     * @param string $art
783
     * @return Dynamic\Animation
784
     */
785
    public function animation($art)
786
    {
787
        return $this->engine->animation($art);
788
    }
789
}
790