Skip to content

Commit 023ef38

Browse files
Merge branch 'master' into constrain-table-43
2 parents 2e5ec11 + 3cec2b6 commit 023ef38

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

lib/cli/Shell.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,22 @@ static public function columns() {
4545
* Returns true if STDOUT output is being redirected to a pipe or a file; false is
4646
* output is being sent directly to the terminal.
4747
*
48+
* If an env variable SHELL_PIPE exists, returned result depends it's
49+
* value. Strings like 1, 0, yes, no, that validate to booleans are accepted.
50+
*
51+
* To enable ASCII formatting even when shell is piped, use the
52+
* ENV variable SHELL_PIPE=0
53+
*
4854
* @return bool
4955
*/
5056
static public function isPiped() {
51-
return (function_exists('posix_isatty') && !posix_isatty(STDOUT));
57+
$shellPipe = getenv('SHELL_PIPE');
58+
59+
if ($shellPipe !== false) {
60+
return filter_var($shellPipe, FILTER_VALIDATE_BOOLEAN);
61+
} else {
62+
return (function_exists('posix_isatty') && !posix_isatty(STDOUT));
63+
}
5264
}
5365
}
5466

0 commit comments

Comments
 (0)