Skip to content

Commit

Permalink
Fixes #11907: Fixed yii\helpers\Console::getScreenSize() on Windows…
Browse files Browse the repository at this point in the history
… was giving out width and height swapped
  • Loading branch information
samdark committed Aug 4, 2016
1 parent 496de65 commit 8a9c8a8
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
1 change: 1 addition & 0 deletions framework/CHANGELOG.md
Expand Up @@ -23,6 +23,7 @@ Yii Framework 2 Change Log
- Enh #12082: Used `jQuery.on(` instead of event method to ensure forwards compatibility (newerton)
- Enh #12028: Add -h|--help option to console command to display help information (pana1990)
- Bug #12053: `./yii migrate/create` was generating wrong code when using `bigPrimaryKey` (VojtechH, samdark)
- Bug #11907: Fixed `yii\helpers\Console::getScreenSize()` on Windows was giving out width and height swapped (Spell6inder, samdark, cebe)

2.0.9 July 11, 2016
-------------------
Expand Down
6 changes: 3 additions & 3 deletions framework/helpers/BaseConsole.php
Expand Up @@ -613,14 +613,14 @@ public static function getScreenSize($refresh = false)
if (static::isRunningOnWindows()) {
$output = [];
exec('mode con', $output);
if (isset($output, $output[1]) && strpos($output[1], 'CON') !== false) {
return $size = [(int) preg_replace('~\D~', '', $output[3]), (int) preg_replace('~\D~', '', $output[4])];
if (isset($output, $output[1]) && preg_match('/con:.*lines:\s+(\d+)\s+columns:\s+(\d+)/mi', implode(' ', $output), $matches)) {
return $size = [(int)$matches[2], (int)$matches[1]];
}
} else {
// try stty if available
$stty = [];
if (exec('stty -a 2>&1', $stty) && preg_match('/rows\s+(\d+);\s*columns\s+(\d+);/mi', implode(' ', $stty), $matches)) {
return $size = [$matches[2], $matches[1]];
return $size = [(int)$matches[2], (int)$matches[1]];
}

// fallback to tput, which may not be updated on terminal resize
Expand Down

4 comments on commit 8a9c8a8

@karakum
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On my system mode con output in RU locale:

Microsoft Windows [Version 6.3.9600]
(c) Корпорация Майкрософт (Microsoft Corporation), 2013. Все права защищены.

d:\>mode con

Состояние устройства CON:
--------------------------
    Строки:                3000
    Столбцы:               225
    Скорость клавиатуры:   27
    Задержка клавиатуры:   0
    Кодовая страница:      866

So current code DON'T WORK

@samdark
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh. That's too bad :( @karakum want to attempt fixing that?

@karakum
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@samdark, previous version just need to swap arguments, like;

616:            if (isset($output, $output[1]) && strpos($output[1], 'CON') !== false) {
617:                return $size = [(int) preg_replace('~\D~', '', $output[4]), (int) preg_replace('~\D~', '', $output[3])];
618:            }

@samdark
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that would work.

Please sign in to comment.