@@ -116,16 +116,25 @@ public static function err( $msg = '' ) {
116116 * @param string $format A valid input format. See `fscanf` for documentation.
117117 * If none is given, all input up to the first newline
118118 * is accepted.
119+ * @param boolean $hide If true will hide what the user types in.
119120 * @return string The input with whitespace trimmed.
120121 * @throws \Exception Thrown if ctrl-D (EOT) is sent as input.
121122 */
122- public static function input ( $ format = null ) {
123+ public static function input ( $ format = null , $ hide = false ) {
124+ if ( $ hide )
125+ Shell::hide ();
126+
123127 if ( $ format ) {
124128 fscanf ( static ::$ in , $ format . "\n" , $ line );
125129 } else {
126130 $ line = fgets ( static ::$ in );
127131 }
128132
133+ if ( $ hide ) {
134+ Shell::hide ( false );
135+ echo "\n" ;
136+ }
137+
129138 if ( $ line === false ) {
130139 throw new \Exception ( 'Caught ^D during input ' );
131140 }
@@ -137,21 +146,22 @@ public static function input( $format = null ) {
137146 * Displays an input prompt. If no default value is provided the prompt will
138147 * continue displaying until input is received.
139148 *
140- * @param string $question The question to ask the user.
141- * @param string $default A default value if the user provides no input.
142- * @param string $marker A string to append to the question and default value
143- * on display.
149+ * @param string $question The question to ask the user.
150+ * @param bool|string $default A default value if the user provides no input.
151+ * @param string $marker A string to append to the question and default value
152+ * on display.
153+ * @param boolean $hide Optionally hides what the user types in.
144154 * @return string The users input.
145155 * @see cli\input()
146156 */
147- public static function prompt ( $ question , $ default = null , $ marker = ': ' ) {
157+ public static function prompt ( $ question , $ default = null , $ marker = ': ' , $ hide = false ) {
148158 if ( $ default && strpos ( $ question , '[ ' ) === false ) {
149159 $ question .= ' [ ' . $ default . '] ' ;
150160 }
151161
152162 while ( true ) {
153163 self ::out ( $ question . $ marker );
154- $ line = self ::input ();
164+ $ line = self ::input ( null , $ hide );
155165
156166 if ( !empty ( $ line ) )
157167 return $ line ;
0 commit comments