Skip to content

Commit

Permalink
[Console] Fix Windows code page support
Browse files Browse the repository at this point in the history
  • Loading branch information
orkan authored and nicolas-grekas committed May 11, 2021
1 parent 56813e5 commit 864568f
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions Helper/QuestionHelper.php
Expand Up @@ -512,7 +512,7 @@ private function readInput($inputStream, Question $question)
$cp = $this->setIOCodepage();
$ret = fgets($inputStream, 4096);

return false !== $ret ? $this->resetIOCodepage($cp, $ret) : false;
return $this->resetIOCodepage($cp, $ret);
}

$multiLineStreamReader = $this->cloneInputStream($inputStream);
Expand All @@ -533,7 +533,7 @@ private function readInput($inputStream, Question $question)
}

/**
* Set console I/O to the host code page.
* Sets console I/O to the host code page.
*
* @return int Previous code page in IBM/EBCDIC format
*/
Expand All @@ -550,13 +550,20 @@ private function setIOCodepage(): int
}

/**
* Set console I/O to the specified code page and convert the user input.
* Sets console I/O to the specified code page and converts the user input.
*
* @param string|false $input
*
* @return string|false
*/
private function resetIOCodepage(int $cp, string $input): string
private function resetIOCodepage(int $cp, $input)
{
if (\function_exists('sapi_windows_cp_set') && 0 < $cp) {
if (0 !== $cp) {
sapi_windows_cp_set($cp);
$input = sapi_windows_cp_conv(sapi_windows_cp_get('oem'), $cp, $input);

if (false !== $input && '' !== $input) {
$input = sapi_windows_cp_conv(sapi_windows_cp_get('oem'), $cp, $input);
}
}

return $input;
Expand Down

0 comments on commit 864568f

Please sign in to comment.