@@ -27,26 +27,27 @@ public static function readline() {
2727 * @param ?array $propositions
2828 * @return string
2929 */
30- public static function question ($ prompt , array $ propositions = null ,array $ options =[]) {
31- $ hiddenProposals =$ options ['hiddenProposals ' ]??[];
32- $ continue =function ($ rep ,$ array ){
33- return \array_search ($ rep , $ array )===false ;
30+ public static function question ($ prompt , array $ propositions = null , array $ options = []) {
31+ $ prompt = ConsoleFormatter::colorize ($ prompt , ConsoleFormatter::BLACK , ConsoleFormatter::BG_YELLOW );
32+ $ hiddenProposals = $ options ['hiddenProposals ' ] ?? [];
33+ $ continue = function ($ rep , $ array ) {
34+ return \array_search ($ rep , $ array ) === false ;
3435 };
35- if (isset ($ options ['default ' ])){
36- $ prompt.= " (default:<b> " . $ options ['default ' ]. "</b>) " ;
36+ if (isset ($ options ['default ' ])) {
37+ $ prompt .= ConsoleFormatter:: formatHtml ( " (default:<b> " . $ options ['default ' ] . "</b>) " ) ;
3738 }
38- if (isset ($ options ['ignoreCase ' ])){
39- $ continue= function ($ rep ,$ array ){
40- return \array_search (\strtolower ($ rep ), \array_map ('strtolower ' , $ array ))===false ;
39+ if (isset ($ options ['ignoreCase ' ])) {
40+ $ continue = function ($ rep , $ array ) {
41+ return \array_search (\strtolower ($ rep ), \array_map ('strtolower ' , $ array )) === false ;
4142 };
4243 }
43- echo ConsoleFormatter:: colorize (ConsoleFormatter:: formatHtml ( $ prompt), ConsoleFormatter:: BLACK , ConsoleFormatter:: BG_YELLOW ) ;
44+ echo $ prompt ;
4445 if (\is_array ($ propositions )) {
4546 if (\count ($ propositions ) > 2 ) {
4647 $ props = "" ;
4748 foreach ($ propositions as $ index => $ prop ) {
48- $ dec= 2 - \strlen (($ index+ 1 ). '' );
49- $ props .= "[ " . ($ index + 1 ) . "] " .str_repeat (' ' ,$ dec ). $ prop . "\n" ;
49+ $ dec = 2 - \strlen (($ index + 1 ) . '' );
50+ $ props .= "[ " . ($ index + 1 ) . "] " . str_repeat (' ' , $ dec ) . $ prop . "\n" ;
5051 }
5152 echo ConsoleFormatter::formatContent ($ props );
5253 do {
@@ -55,26 +56,35 @@ public static function question($prompt, array $propositions = null,array $optio
5556 $ answer = $ propositions [(int ) $ answer - 1 ];
5657 } else {
5758 echo " ( " . implode ("/ " , $ propositions ) . ") \n" ;
58- $ propositions= \array_merge ($ propositions ,$ hiddenProposals );
59+ $ propositions = \array_merge ($ propositions , $ hiddenProposals );
5960 do {
6061 $ answer = self ::readline ();
61- } while ($ continue ($ answer ,$ propositions ));
62+ } while ($ continue ($ answer , $ propositions ));
6263 }
6364 } else {
6465 $ answer = self ::readline ();
6566 }
66- if (isset ($ options ['default ' ]) && $ answer== '' ){
67- $ answer= $ options ['default ' ];
67+ if (isset ($ options ['default ' ]) && $ answer == '' ) {
68+ $ answer = $ options ['default ' ];
6869 }
6970 return $ answer ;
7071 }
71-
72- public static function yesNoQuestion ($ prompt , array $ propositions = ['yes ' ,'no ' ],array $ options =[]){
73- return self ::question ($ prompt ,$ propositions ,['ignoreCase ' =>true ,'hiddenProposals ' =>['y ' ,'n ' ]]);
72+
73+ public static function yesNoQuestion ($ prompt , array $ propositions = [
74+ 'yes ' ,
75+ 'no '
76+ ], array $ options = []) {
77+ return self ::question ($ prompt , $ propositions , [
78+ 'ignoreCase ' => true ,
79+ 'hiddenProposals ' => [
80+ 'y ' ,
81+ 'n '
82+ ]
83+ ]);
7484 }
75-
76- public static function explodeResponse (string $ response , $ callback= 'trim ' ,string $ separator= ', ' ){
77- return \array_map ($ callback ,\array_filter ( \explode ($ separator , \trim ($ response )), 'strlen ' ));
85+
86+ public static function explodeResponse (string $ response , $ callback = 'trim ' , string $ separator = ', ' ) {
87+ return \array_map ($ callback , \array_filter (\explode ($ separator , \trim ($ response )), 'strlen ' ));
7888 }
7989
8090 /**
0 commit comments