Skip to content

Commit a4e18af

Browse files
committed
Check COLUMNS early and on all platforms
1 parent 625f989 commit a4e18af

1 file changed

Lines changed: 8 additions & 10 deletions

File tree

lib/cli/Shell.php

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ static public function columns() {
3131
$columns = null;
3232
}
3333
if ( null === $columns ) {
34-
if ( function_exists( 'exec' ) ) {
34+
if ( ! ( $columns = (int) getenv( 'COLUMNS' ) ) && function_exists( 'exec' ) ) {
3535
if ( self::is_windows() ) {
3636
// Cater for shells such as Cygwin and Git bash where `mode CON` returns an incorrect value for columns.
3737
if ( ( $shell = getenv( 'SHELL' ) ) && preg_match( '/(?:bash|zsh)(?:\.exe)?$/', $shell ) && getenv( 'TERM' ) ) {
@@ -49,15 +49,13 @@ static public function columns() {
4949
}
5050
}
5151
} else {
52-
if ( ! ( $columns = (int) getenv( 'COLUMNS' ) ) ) {
53-
$size = exec( '/usr/bin/env stty size 2>/dev/null' );
54-
if ( '' !== $size && preg_match( '/[0-9]+ ([0-9]+)/', $size, $matches ) ) {
55-
$columns = (int) $matches[1];
56-
}
57-
if ( ! $columns ) {
58-
if ( getenv( 'TERM' ) ) {
59-
$columns = (int) exec( '/usr/bin/env tput cols 2>/dev/null' );
60-
}
52+
$size = exec( '/usr/bin/env stty size 2>/dev/null' );
53+
if ( '' !== $size && preg_match( '/[0-9]+ ([0-9]+)/', $size, $matches ) ) {
54+
$columns = (int) $matches[1];
55+
}
56+
if ( ! $columns ) {
57+
if ( getenv( 'TERM' ) ) {
58+
$columns = (int) exec( '/usr/bin/env tput cols 2>/dev/null' );
6159
}
6260
}
6361
}

0 commit comments

Comments
 (0)