37
37
* @license MIT
38
38
*
39
39
* @link https://github.com/adhocore/cli
40
- *
41
- * @method Writer bgBlack($text, $eol = false)
42
- * @method Writer bgBlue($text, $eol = false)
43
- * @method Writer bgCyan($text, $eol = false)
44
- * @method Writer bgGreen($text, $eol = false)
45
- * @method Writer bgPurple($text, $eol = false)
46
- * @method Writer bgRed($text, $eol = false)
47
- * @method Writer bgWhite($text, $eol = false)
48
- * @method Writer bgYellow($text, $eol = false)
49
- * @method Writer black($text, $eol = false)
50
- * @method Writer blackBgBlue($text, $eol = false)
51
- * @method Writer blackBgCyan($text, $eol = false)
52
- * @method Writer blackBgGreen($text, $eol = false)
53
- * @method Writer blackBgPurple($text, $eol = false)
54
- * @method Writer blackBgRed($text, $eol = false)
55
- * @method Writer blackBgWhite($text, $eol = false)
56
- * @method Writer blackBgYellow($text, $eol = false)
57
- * @method Writer blue($text, $eol = false)
58
- * @method Writer blueBgBlack($text, $eol = false)
59
- * @method Writer blueBgCyan($text, $eol = false)
60
- * @method Writer blueBgGreen($text, $eol = false)
61
- * @method Writer blueBgPurple($text, $eol = false)
62
- * @method Writer blueBgRed($text, $eol = false)
63
- * @method Writer blueBgWhite($text, $eol = false)
64
- * @method Writer blueBgYellow($text, $eol = false)
65
- * @method Writer bold($text, $eol = false)
66
- * @method Writer boldBlack($text, $eol = false)
67
- * @method Writer boldBlackBgBlue($text, $eol = false)
68
- * @method Writer boldBlackBgCyan($text, $eol = false)
69
- * @method Writer boldBlackBgGreen($text, $eol = false)
70
- * @method Writer boldBlackBgPurple($text, $eol = false)
71
- * @method Writer boldBlackBgRed($text, $eol = false)
72
- * @method Writer boldBlackBgWhite($text, $eol = false)
73
- * @method Writer boldBlackBgYellow($text, $eol = false)
74
- * @method Writer boldBlue($text, $eol = false)
75
- * @method Writer boldBlueBgBlack($text, $eol = false)
76
- * @method Writer boldBlueBgCyan($text, $eol = false)
77
- * @method Writer boldBlueBgGreen($text, $eol = false)
78
- * @method Writer boldBlueBgPurple($text, $eol = false)
79
- * @method Writer boldBlueBgRed($text, $eol = false)
80
- * @method Writer boldBlueBgWhite($text, $eol = false)
81
- * @method Writer boldBlueBgYellow($text, $eol = false)
82
- * @method Writer boldCyan($text, $eol = false)
83
- * @method Writer boldCyanBgBlack($text, $eol = false)
84
- * @method Writer boldCyanBgBlue($text, $eol = false)
85
- * @method Writer boldCyanBgGreen($text, $eol = false)
86
- * @method Writer boldCyanBgPurple($text, $eol = false)
87
- * @method Writer boldCyanBgRed($text, $eol = false)
88
- * @method Writer boldCyanBgWhite($text, $eol = false)
89
- * @method Writer boldCyanBgYellow($text, $eol = false)
90
- * @method Writer boldGreen($text, $eol = false)
91
- * @method Writer boldGreenBgBlack($text, $eol = false)
92
- * @method Writer boldGreenBgBlue($text, $eol = false)
93
- * @method Writer boldGreenBgCyan($text, $eol = false)
94
- * @method Writer boldGreenBgPurple($text, $eol = false)
95
- * @method Writer boldGreenBgRed($text, $eol = false)
96
- * @method Writer boldGreenBgWhite($text, $eol = false)
97
- * @method Writer boldGreenBgYellow($text, $eol = false)
98
- * @method Writer boldPurple($text, $eol = false)
99
- * @method Writer boldPurpleBgBlack($text, $eol = false)
100
- * @method Writer boldPurpleBgBlue($text, $eol = false)
101
- * @method Writer boldPurpleBgCyan($text, $eol = false)
102
- * @method Writer boldPurpleBgGreen($text, $eol = false)
103
- * @method Writer boldPurpleBgRed($text, $eol = false)
104
- * @method Writer boldPurpleBgWhite($text, $eol = false)
105
- * @method Writer boldPurpleBgYellow($text, $eol = false)
106
- * @method Writer boldRed($text, $eol = false)
107
- * @method Writer boldRedBgBlack($text, $eol = false)
108
- * @method Writer boldRedBgBlue($text, $eol = false)
109
- * @method Writer boldRedBgCyan($text, $eol = false)
110
- * @method Writer boldRedBgGreen($text, $eol = false)
111
- * @method Writer boldRedBgPurple($text, $eol = false)
112
- * @method Writer boldRedBgWhite($text, $eol = false)
113
- * @method Writer boldRedBgYellow($text, $eol = false)
114
- * @method Writer boldWhite($text, $eol = false)
115
- * @method Writer boldWhiteBgBlack($text, $eol = false)
116
- * @method Writer boldWhiteBgBlue($text, $eol = false)
117
- * @method Writer boldWhiteBgCyan($text, $eol = false)
118
- * @method Writer boldWhiteBgGreen($text, $eol = false)
119
- * @method Writer boldWhiteBgPurple($text, $eol = false)
120
- * @method Writer boldWhiteBgRed($text, $eol = false)
121
- * @method Writer boldWhiteBgYellow($text, $eol = false)
122
- * @method Writer boldYellow($text, $eol = false)
123
- * @method Writer boldYellowBgBlack($text, $eol = false)
124
- * @method Writer boldYellowBgBlue($text, $eol = false)
125
- * @method Writer boldYellowBgCyan($text, $eol = false)
126
- * @method Writer boldYellowBgGreen($text, $eol = false)
127
- * @method Writer boldYellowBgPurple($text, $eol = false)
128
- * @method Writer boldYellowBgRed($text, $eol = false)
129
- * @method Writer boldYellowBgWhite($text, $eol = false)
130
- * @method Writer colors($text)
131
- * @method Writer comment($text, $eol = false)
132
- * @method Writer cyan($text, $eol = false)
133
- * @method Writer cyanBgBlack($text, $eol = false)
134
- * @method Writer cyanBgBlue($text, $eol = false)
135
- * @method Writer cyanBgGreen($text, $eol = false)
136
- * @method Writer cyanBgPurple($text, $eol = false)
137
- * @method Writer cyanBgRed($text, $eol = false)
138
- * @method Writer cyanBgWhite($text, $eol = false)
139
- * @method Writer cyanBgYellow($text, $eol = false)
140
- * @method Writer eol(int $n = 1)
141
- * @method Writer error($text, $eol = false)
142
- * @method Writer green($text, $eol = false)
143
- * @method Writer greenBgBlack($text, $eol = false)
144
- * @method Writer greenBgBlue($text, $eol = false)
145
- * @method Writer greenBgCyan($text, $eol = false)
146
- * @method Writer greenBgPurple($text, $eol = false)
147
- * @method Writer greenBgRed($text, $eol = false)
148
- * @method Writer greenBgWhite($text, $eol = false)
149
- * @method Writer greenBgYellow($text, $eol = false)
150
- * @method Writer info($text, $eol = false)
151
- * @method Writer ok($text, $eol = false)
152
- * @method Writer purple($text, $eol = false)
153
- * @method Writer purpleBgBlack($text, $eol = false)
154
- * @method Writer purpleBgBlue($text, $eol = false)
155
- * @method Writer purpleBgCyan($text, $eol = false)
156
- * @method Writer purpleBgGreen($text, $eol = false)
157
- * @method Writer purpleBgRed($text, $eol = false)
158
- * @method Writer purpleBgWhite($text, $eol = false)
159
- * @method Writer purpleBgYellow($text, $eol = false)
160
- * @method Writer red($text, $eol = false)
161
- * @method Writer redBgBlack($text, $eol = false)
162
- * @method Writer redBgBlue($text, $eol = false)
163
- * @method Writer redBgCyan($text, $eol = false)
164
- * @method Writer redBgGreen($text, $eol = false)
165
- * @method Writer redBgPurple($text, $eol = false)
166
- * @method Writer redBgWhite($text, $eol = false)
167
- * @method Writer redBgYellow($text, $eol = false)
168
- * @method Writer table(array $rows, array $styles = [])
169
- * @method Writer warn($text, $eol = false)
170
- * @method Writer white($text, $eol = false)
171
- * @method Writer yellow($text, $eol = false)
172
- * @method Writer yellowBgBlack($text, $eol = false)
173
- * @method Writer yellowBgBlue($text, $eol = false)
174
- * @method Writer yellowBgCyan($text, $eol = false)
175
- * @method Writer yellowBgGreen($text, $eol = false)
176
- * @method Writer yellowBgPurple($text, $eol = false)
177
- * @method Writer yellowBgRed($text, $eol = false)
178
- * @method Writer yellowBgWhite($text, $eol = false)
179
40
*/
180
41
class Interactor
181
42
{
@@ -241,7 +102,7 @@ public function confirm(string $text, string $default = 'y'): bool
241
102
*/
242
103
public function choice (string $ text , array $ choices , $ default = null , bool $ case = false ): mixed
243
104
{
244
- $ this ->writer ->yellow ($ text );
105
+ $ this ->writer ->question ($ text );
245
106
246
107
$ this ->listOptions ($ choices , $ default , false );
247
108
@@ -262,7 +123,7 @@ public function choice(string $text, array $choices, $default = null, bool $case
262
123
*/
263
124
public function choices (string $ text , array $ choices , $ default = null , bool $ case = false ): mixed
264
125
{
265
- $ this ->writer ->yellow ($ text );
126
+ $ this ->writer ->question ($ text );
266
127
267
128
$ this ->listOptions ($ choices , $ default , true );
268
129
@@ -300,7 +161,7 @@ public function prompt(string $text, $default = null, ?callable $fn = null, int
300
161
$ hidden = func_get_args ()[4 ] ?? false ;
301
162
$ readFn = ['read ' , 'readHidden ' ][(int ) $ hidden ];
302
163
303
- $ this ->writer ->yellow ($ text )->comment (null !== $ default ? " [ $ default]: " : ': ' );
164
+ $ this ->writer ->question ($ text )->answer (null !== $ default ? " [ $ default]: " : ': ' );
304
165
305
166
try {
306
167
$ input = $ this ->reader ->{$ readFn }($ default , $ fn );
@@ -310,7 +171,7 @@ public function prompt(string $text, $default = null, ?callable $fn = null, int
310
171
}
311
172
312
173
if ($ retry > 0 && $ input === '' ) {
313
- $ this ->writer ->bgRed ($ error , true );
174
+ $ this ->writer ->error ($ error , true );
314
175
315
176
return $ this ->prompt ($ text , $ default , $ fn , $ retry - 1 , $ hidden );
316
177
}
@@ -351,12 +212,12 @@ protected function listOptions(array $choices, $default = null, bool $multi = fa
351
212
$ maxLen = max (array_map ('strlen ' , array_keys ($ choices )));
352
213
353
214
foreach ($ choices as $ choice => $ desc ) {
354
- $ this ->writer ->eol ()->cyan (str_pad (" [ $ choice] " , $ maxLen + 6 ))->comment ($ desc );
215
+ $ this ->writer ->eol ()->choice (str_pad (" [ $ choice] " , $ maxLen + 6 ))->answer ($ desc );
355
216
}
356
217
357
218
$ label = $ multi ? 'Choices (comma separated) ' : 'Choice ' ;
358
219
359
- $ this ->writer ->eol ()->yellow ($ label );
220
+ $ this ->writer ->eol ()->question ($ label );
360
221
361
222
return $ this ->promptOptions (array_keys ($ choices ), $ default );
362
223
}
@@ -369,7 +230,7 @@ protected function promptOptions(array $choices, mixed $default): self
369
230
$ options = '' ;
370
231
371
232
foreach ($ choices as $ choice ) {
372
- $ style = in_array ($ choice , (array ) $ default ) ? 'boldCyan ' : 'cyan ' ;
233
+ $ style = in_array ($ choice , (array ) $ default ) ? 'boldChoice ' : 'choice ' ;
373
234
$ options .= "/< $ style> $ choice</end> " ;
374
235
}
375
236
0 commit comments