Skip to content

Commit

Permalink
Avoid some exceptions when running in non CLI context
Browse files Browse the repository at this point in the history
  • Loading branch information
RyanNerd committed Jan 22, 2022
1 parent 5c717c3 commit 643a560
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions src/Util/System/Linux.php
Expand Up @@ -86,19 +86,23 @@ protected function systemHasAnsiSupport()
if ('Hyper' === getenv('TERM_PROGRAM')) {
return true;
}

$stream = STDOUT;

if (function_exists('stream_isatty')) {
return @stream_isatty($stream);
}

if (function_exists('posix_isatty')) {
return @posix_isatty($stream);
if (defined(STDOUT)) {
$stream = STDOUT;

if (function_exists('stream_isatty')) {
return @stream_isatty($stream);
}

if (function_exists('posix_isatty')) {
return @posix_isatty($stream);
}

$stat = @fstat($stream);
// Check if formatted mode is S_IFCHR
return $stat && 0020000 === ($stat['mode'] & 0170000);
}

$stat = @fstat($stream);
// Check if formatted mode is S_IFCHR
return $stat ? 0020000 === ($stat['mode'] & 0170000) : false;
return false;
}
}

0 comments on commit 643a560

Please sign in to comment.