comparison vendor/symfony/console/Helper/QuestionHelper.php @ 18:af1871eacc83

Update to Drupal core 8.7.1
author Chris Cannam
date Thu, 09 May 2019 15:33:08 +0100
parents 129ea1e6d783
children
comparison
equal deleted inserted replaced
17:129ea1e6d783 18:af1871eacc83
47 } 47 }
48 48
49 if (!$input->isInteractive()) { 49 if (!$input->isInteractive()) {
50 $default = $question->getDefault(); 50 $default = $question->getDefault();
51 51
52 if (null !== $default && $question instanceof ChoiceQuestion) { 52 if (null === $default) {
53 return $default;
54 }
55
56 if ($validator = $question->getValidator()) {
57 return \call_user_func($question->getValidator(), $default);
58 } elseif ($question instanceof ChoiceQuestion) {
53 $choices = $question->getChoices(); 59 $choices = $question->getChoices();
54 60
55 if (!$question->isMultiselect()) { 61 if (!$question->isMultiselect()) {
56 return isset($choices[$default]) ? $choices[$default] : $default; 62 return isset($choices[$default]) ? $choices[$default] : $default;
57 } 63 }
164 } 170 }
165 171
166 if (false === $ret) { 172 if (false === $ret) {
167 $ret = fgets($inputStream, 4096); 173 $ret = fgets($inputStream, 4096);
168 if (false === $ret) { 174 if (false === $ret) {
169 throw new RuntimeException('Aborted'); 175 throw new RuntimeException('Aborted.');
170 } 176 }
171 $ret = trim($ret); 177 $ret = trim($ret);
172 } 178 }
173 } else { 179 } else {
174 $ret = trim($this->autocomplete($output, $question, $inputStream, \is_array($autocomplete) ? $autocomplete : iterator_to_array($autocomplete, false))); 180 $ret = trim($this->autocomplete($output, $question, $inputStream, \is_array($autocomplete) ? $autocomplete : iterator_to_array($autocomplete, false)));
250 256
251 // Read a keypress 257 // Read a keypress
252 while (!feof($inputStream)) { 258 while (!feof($inputStream)) {
253 $c = fread($inputStream, 1); 259 $c = fread($inputStream, 1);
254 260
255 // Backspace Character 261 // as opposed to fgets(), fread() returns an empty string when the stream content is empty, not false.
256 if ("\177" === $c) { 262 if (false === $c || ('' === $ret && '' === $c && null === $question->getDefault())) {
263 shell_exec(sprintf('stty %s', $sttyMode));
264 throw new RuntimeException('Aborted.');
265 } elseif ("\177" === $c) { // Backspace Character
257 if (0 === $numMatches && 0 !== $i) { 266 if (0 === $numMatches && 0 !== $i) {
258 --$i; 267 --$i;
259 // Move cursor backwards 268 // Move cursor backwards
260 $output->write("\033[1D"); 269 $output->write("\033[1D");
261 } 270 }
304 $numMatches = 0; 313 $numMatches = 0;
305 } 314 }
306 315
307 continue; 316 continue;
308 } else { 317 } else {
318 if ("\x80" <= $c) {
319 $c .= fread($inputStream, ["\xC0" => 1, "\xD0" => 1, "\xE0" => 2, "\xF0" => 3][$c & "\xF0"]);
320 }
321
309 $output->write($c); 322 $output->write($c);
310 $ret .= $c; 323 $ret .= $c;
311 ++$i; 324 ++$i;
312 325
313 $numMatches = 0; 326 $numMatches = 0;
378 shell_exec('stty -echo'); 391 shell_exec('stty -echo');
379 $value = fgets($inputStream, 4096); 392 $value = fgets($inputStream, 4096);
380 shell_exec(sprintf('stty %s', $sttyMode)); 393 shell_exec(sprintf('stty %s', $sttyMode));
381 394
382 if (false === $value) { 395 if (false === $value) {
383 throw new RuntimeException('Aborted'); 396 throw new RuntimeException('Aborted.');
384 } 397 }
385 398
386 $value = trim($value); 399 $value = trim($value);
387 $output->writeln(''); 400 $output->writeln('');
388 401