Beispiel #1
0
 public static function is_tty()
 {
     if (self::$is_tty === null) {
         self::$is_tty = function_exists('posix_isatty') ? posix_isatty(STDOUT) : false;
     }
     return self::$is_tty;
 }
 /**
  * Initializes default configuration.
  */
 public function __construct()
 {
     $templateDir = self::isInstalledByPear() ? '@data_dir@' . DIRECTORY_SEPARATOR . 'ApiGen' : realpath(__DIR__ . DIRECTORY_SEPARATOR . '..');
     self::$defaultConfig['templateConfig'] = $templateDir . DIRECTORY_SEPARATOR . 'templates' . DIRECTORY_SEPARATOR . 'default' . DIRECTORY_SEPARATOR . 'config.neon';
     self::$defaultConfig['colors'] = 'WIN' === substr(PHP_OS, 0, 3) ? false : (function_exists('posix_isatty') && defined('STDOUT') ? posix_isatty(STDOUT) : true);
     $this->config = self::$defaultConfig;
 }
Beispiel #3
0
 /**
  * Returns true if the stream supports colorization.
  *
  * Colorization is disabled if not supported by the stream:
  *
  *  -  Windows without Ansicon, ConEmu or Babun
  *  -  non tty consoles
  *
  * @return bool true if the stream supports colorization, false otherwise
  *
  * @link https://github.com/symfony/Console/blob/master/Output/StreamOutput.php#L95-L102
  * @codeCoverageIgnore
  */
 public function isSupported()
 {
     if (DIRECTORY_SEPARATOR == '\\') {
         return false !== getenv('ANSICON') || 'ON' === getenv('ConEmuANSI') || false !== getenv('BABUN_HOME');
     }
     return false !== getenv('BABUN_HOME') || function_exists('posix_isatty') && @posix_isatty(STDOUT);
 }
Beispiel #4
0
 static function supports_colour()
 {
     if (!defined('STDOUT')) {
         define('STDOUT', fopen("php://stdout", "w"));
     }
     return @posix_isatty(STDOUT);
 }
Beispiel #5
0
 function __construct()
 {
     if (DIRECTORY_SEPARATOR == '\\' || !function_exists('posix_isatty') || !@posix_isatty(STDOUT)) {
         self::$colorizedOutputSupported = false;
     }
     $this->registerStyle('PARAMETER', array('fg' => 'cyan'))->registerStyle('COMMENT', array('fg' => 'green'))->registerStyle('INFO', array('fg' => 'blue'))->registerStyle('WARNING', array('fg' => 'magenta'))->registerStyle('ERROR', array('fg' => 'red', 'bold' => true))->registerStyle('ACTION_DELETE', array('fg' => 'red'))->registerStyle('BOLD', array('bold' => true))->registerStyle('ITALIC', array('italic' => true));
 }
Beispiel #6
0
 /**
  * Configures colored output.
  * @return void
  */
 public static function setupColors()
 {
     self::$useColors = getenv(self::COLORS) !== FALSE ? (bool) getenv(self::COLORS) : (PHP_SAPI === 'cli' || PHP_SAPI === 'phpdbg') && (function_exists('posix_isatty') && posix_isatty(STDOUT) || getenv('ConEmuANSI') === 'ON' || getenv('ANSICON') !== FALSE) || getenv('TERM') === 'xterm-256color';
     ob_start(function ($s) {
         return self::$useColors ? $s : Dumper::removeColors($s);
     }, 1, FALSE);
 }
Beispiel #7
0
 /**
  * Returns true if the stream supports colorization.
  *
  * Colorization is disabled if not supported by the stream:
  *
  *  -  Windows without Ansicon, ConEmu or Mintty
  *  -  non tty consoles
  *
  * @return bool true if the stream supports colorization, false otherwise
  */
 protected function hasColorSupport()
 {
     if (DIRECTORY_SEPARATOR === '\\') {
         return false !== getenv('ANSICON') || 'ON' === getenv('ConEmuANSI') || 'xterm' === getenv('TERM');
     }
     return function_exists('posix_isatty') && @posix_isatty($this->stream);
 }
Beispiel #8
0
/**
* Code from Symfony/Component/Console/Output/StreamOutput.php
*/
function hasColorSupport()
{
    if (DIRECTORY_SEPARATOR == '\\') {
        return false !== getenv('ANSICON') || 'ON' === getenv('ConEmuANSI');
    }
    return function_exists('posix_isatty') && @posix_isatty(STDOUT);
}
Beispiel #9
0
 public function isInteractive()
 {
     if (null === $this->isInteractive) {
         $this->isInteractive = 'cli' === php_sapi_name() && (function_exists('posix_isatty') && @posix_isatty(STDOUT) || 'ON' === getenv('ConEmuANSI') || false !== getenv('ANSICON'));
     }
     return $this->isInteractive;
 }
Beispiel #10
0
 /**
  * Configures colored output.
  * @return void
  */
 public static function setupColors()
 {
     self::$useColors = getenv(self::COLORS) !== FALSE ? (bool) getenv(self::COLORS) : PHP_SAPI === 'cli' && (function_exists('posix_isatty') && posix_isatty(STDOUT) || getenv('ConEmuANSI') === 'ON' || getenv('ANSICON') !== FALSE);
     ob_start(function ($s) {
         return Environment::$useColors ? $s : Dumper::removeColors($s);
     }, PHP_VERSION_ID < 50400 ? 2 : 1);
 }
 /**
  * {@inheritdoc}
  */
 public function supportsAnsi()
 {
     if (DIRECTORY_SEPARATOR === '\\') {
         return false !== getenv('ANSICON') || 'ON' === getenv('ConEmuANSI') || 'xterm' === getenv('TERM');
     }
     return function_exists('posix_isatty') && @posix_isatty($this->stream);
 }
 public static function call_phing($task, $target, $build_file = '', $options = array())
 {
     $args = array();
     foreach ($options as $key => $value) {
         $args[] = "-D{$key}={$value}";
     }
     if ($build_file) {
         $args[] = '-f';
         $args[] = realpath($build_file);
     }
     if (!$task->is_verbose()) {
         $args[] = '-q';
     }
     if (is_array($target)) {
         $args = array_merge($args, $target);
     } else {
         $args[] = $target;
     }
     if (DIRECTORY_SEPARATOR != '\\' && (function_exists('posix_isatty') && @posix_isatty(STDOUT))) {
         $args[] = '-logger';
         $args[] = 'phing.listener.AnsiColorLogger';
     }
     Phing::startup();
     Phing::setProperty('phing.home', getenv('PHING_HOME'));
     $m = new pakePhing();
     $m->execute($args);
     $m->runBuild();
 }
Beispiel #13
0
 /**
  * Initialize
  * @param array
  * @param array
  * @param array
  * @param Executor
  * @param bool
  */
 public function __construct(array $argv, array $envp, array $descriptors, Executor $executor, $interactive = NULL)
 {
     $this->argv = $argv;
     $this->envp = $envp;
     if (!isset($this->envp['PS1'])) {
         $this->envp['PS1'] = self::DEFAULT_PS1;
     }
     if (!isset($this->envp['PS2'])) {
         $this->envp['PS2'] = self::DEFAULT_PS2;
     }
     $this->descriptors = $descriptors;
     list($this->stdin, $this->stdout, $this->stderr) = $this->descriptors;
     $this->executor = $executor;
     if (!is_bool($interactive)) {
         $interactive = FALSE;
         if (function_exists('posix_isatty') && @posix_isatty($descriptors[0])) {
             $interactive = TRUE;
         }
     }
     $this->interactive = $interactive;
     if ($this->interactive) {
         $descriptors[0] = fopen('sh-interactiveinput://', NULL, FALSE, stream_context_create(array('sh-interactiveinput' => array('handle' => $this->stdin, 'out' => $this->stdout))));
         $this->descriptors[1] = fopen('sh-interactiveoutput://', NULL, FALSE, stream_context_create(array('sh-interactiveoutput' => array('handle' => $this->descriptors[1]))));
         $this->descriptors[2] = fopen('sh-interactiveoutput://', NULL, FALSE, stream_context_create(array('sh-interactiveoutput' => array('handle' => $this->descriptors[2]))));
     }
 }
 public function run()
 {
     $method = $this->getArgument('method', array());
     if (count($method) !== 1) {
         throw new ArcanistUsageException(pht('Provide exactly one Conduit method name.'));
     }
     $method = reset($method);
     $console = PhutilConsole::getConsole();
     if (!function_exists('posix_isatty') || posix_isatty(STDIN)) {
         $console->writeErr("%s\n", pht('Waiting for JSON parameters on stdin...'));
     }
     $params = @file_get_contents('php://stdin');
     try {
         $params = phutil_json_decode($params);
     } catch (PhutilJSONParserException $ex) {
         throw new ArcanistUsageException(pht('Provide method parameters on stdin as a JSON blob.'));
     }
     $error = null;
     $error_message = null;
     try {
         $result = $this->getConduit()->callMethodSynchronous($method, $params);
     } catch (ConduitClientException $ex) {
         $error = $ex->getErrorCode();
         $error_message = $ex->getMessage();
         $result = null;
     }
     echo json_encode(array('error' => $error, 'errorMessage' => $error_message, 'response' => $result)) . "\n";
     return 0;
 }
Beispiel #15
0
 public function run($folder)
 {
     set_time_limit(0);
     $this->useColors = PHP_SAPI === 'cli' && (function_exists('posix_isatty') && posix_isatty(STDOUT) || getenv('ConEmuANSI') === 'ON' || getenv('ANSICON') !== FALSE);
     if ($this->readOnly) {
         echo "Running in read-only mode\n";
     }
     echo "Scanning folder {$this->color('white', $folder)}\n";
     $counter = 0;
     $success = TRUE;
     foreach (Nette\Utils\Finder::findFiles($this->accept)->exclude($this->ignore)->from($folder)->exclude($this->ignore) as $file) {
         echo str_pad(str_repeat('.', $counter++ % 40), 40), "\r";
         $orig = $s = file_get_contents($file);
         $this->file = ltrim(substr($file, strlen($folder)), '/\\');
         $this->error = FALSE;
         foreach ($this->tasks as $task) {
             $res = $task($this, $s);
             if ($this->error) {
                 $success = FALSE;
                 continue 2;
             } elseif (is_string($res)) {
                 $s = $res;
             }
         }
         if ($s !== $orig && !$this->readOnly) {
             file_put_contents($file, $s);
         }
     }
     echo str_pad('', 40), "\rDone.\n";
     return $success;
 }
 /**
  * Set color
  *
  * @param   bool color
  * @return  self
  */
 public function setColor($color)
 {
     if (null === $color) {
         $color = $this->out instanceof ConsoleOutputStream && function_exists('posix_isatty') ? posix_isatty(STDOUT) : true;
     }
     $this->colored = $color;
 }
Beispiel #17
0
 /**
  * Identify if console supports colors
  *
  * @return boolean
  */
 public static function isSupportedShell()
 {
     if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
         return false !== getenv('ANSICON') || 'ON' === getenv('ConEmuANSI') || 'xterm' === getenv('TERM');
     }
     return defined('STDOUT') && function_exists('posix_isatty') && posix_isatty(STDOUT);
 }
Beispiel #18
0
 /**
  * Returns true if the stream supports colorization.
  *
  * Colorization is disabled if not supported by the stream:
  *
  *  -  Windows != 10.0.10586 without Ansicon, ConEmu or Mintty
  *  -  non tty consoles
  *
  * @return bool true if the stream supports colorization, false otherwise
  */
 protected function hasColorSupport()
 {
     if (DIRECTORY_SEPARATOR === '\\') {
         return '10.0.10586' === PHP_WINDOWS_VERSION_MAJOR . '.' . PHP_WINDOWS_VERSION_MINOR . '.' . PHP_WINDOWS_VERSION_BUILD || false !== getenv('ANSICON') || 'ON' === getenv('ConEmuANSI') || 'xterm' === getenv('TERM');
     }
     return function_exists('posix_isatty') && @posix_isatty($this->stream);
 }
Beispiel #19
0
 /**
  * @return bool
  */
 public function isSupported()
 {
     if (DIRECTORY_SEPARATOR === '\\') {
         return getenv('ANSICON') !== false || getenv('ConEmuANSI') === 'ON';
     }
     return function_exists('posix_isatty') && @posix_isatty(STDOUT);
 }
Beispiel #20
0
 public function main()
 {
     $this->_initDb();
     $cli = new \Console_CommandLine_Result();
     $cli->options = $this->params;
     $cli->args = array('files' => $this->args);
     // Check if we can use colors
     if ($cli->options['color'] === 'auto') {
         $cli->options['color'] = DIRECTORY_SEPARATOR != '\\' && function_exists('posix_isatty') && @posix_isatty(STDOUT);
     } else {
         $cli->options['color'] = filter_var($cli->options['color'], FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE);
     }
     if (empty($cli->args['files'])) {
         $cli->args['files'] = array(ROOT . DS . 'spec');
     }
     if (!($cli->options['verbose'] || $cli->options['debug'])) {
         set_error_handler(array($this, 'skipWarning'), E_WARNING | E_NOTICE);
     }
     if ($cli->options['dump']) {
         $module = new DrSlump\Spec\Cli\Modules\Dump($cli);
         $module->run();
     } else {
         $module = new DrSlump\Spec\Cli\Modules\Test($cli);
         $module->run();
     }
 }
Beispiel #21
0
 /**
  * Configures PHP environment.
  * @return void
  */
 public static function setup()
 {
     self::$useColors = getenv('NETTE_TESTER_COLORS') !== FALSE ? (bool) getenv('NETTE_TESTER_COLORS') : PHP_SAPI === 'cli' && (function_exists('posix_isatty') && posix_isatty(STDOUT) || getenv('ConEmuANSI') === 'ON' || getenv('ANSICON') !== FALSE);
     class_exists('Tester\\Runner\\Job');
     class_exists('Tester\\Dumper');
     class_exists('Tester\\Assert');
     error_reporting(E_ALL | E_STRICT);
     ini_set('display_errors', TRUE);
     ini_set('html_errors', FALSE);
     ini_set('log_errors', FALSE);
     set_exception_handler(array(__CLASS__, 'handleException'));
     set_error_handler(function ($severity, $message, $file, $line) {
         if (in_array($severity, array(E_RECOVERABLE_ERROR, E_USER_ERROR)) || ($severity & error_reporting()) === $severity) {
             Environment::handleException(new \ErrorException($message, 0, $severity, $file, $line));
         }
         return FALSE;
     });
     register_shutdown_function(function () {
         Assert::$onFailure = array(__CLASS__, 'handleException');
         // note that Runner is unable to catch this errors in CLI & PHP 5.4.0 - 5.4.6 due PHP bug #62725
         $error = error_get_last();
         if (in_array($error['type'], array(E_ERROR, E_CORE_ERROR, E_COMPILE_ERROR, E_PARSE)) && ($error['type'] & error_reporting()) !== $error['type']) {
             register_shutdown_function(function () use($error) {
                 echo "\nFatal error: {$error['message']} in {$error['file']} on line {$error['line']}\n";
             });
         }
     });
 }
Beispiel #22
0
 static function colorize($text = '', $parameters = array(), $stream = STDOUT)
 {
     // disable colors if not supported (windows or non tty console)
     if (DIRECTORY_SEPARATOR == '\\' || !function_exists('posix_isatty') || !@posix_isatty($stream)) {
         return $text;
     }
     static $options = array('bold' => 1, 'underscore' => 4, 'blink' => 5, 'reverse' => 7, 'conceal' => 8);
     static $foreground = array('black' => 30, 'red' => 31, 'green' => 32, 'yellow' => 33, 'blue' => 34, 'magenta' => 35, 'cyan' => 36, 'white' => 37);
     static $background = array('black' => 40, 'red' => 41, 'green' => 42, 'yellow' => 43, 'blue' => 44, 'magenta' => 45, 'cyan' => 46, 'white' => 47);
     if (!is_array($parameters) && isset(self::$styles[$parameters])) {
         $parameters = self::$styles[$parameters];
     }
     $codes = array();
     if (isset($parameters['fg'])) {
         $codes[] = $foreground[$parameters['fg']];
     }
     if (isset($parameters['bg'])) {
         $codes[] = $background[$parameters['bg']];
     }
     foreach ($options as $option => $value) {
         if (isset($parameters[$option]) && $parameters[$option]) {
             $codes[] = $value;
         }
     }
     return "[" . implode(';', $codes) . 'm' . $text . "";
 }
Beispiel #23
0
 /**
  * @link https://github.com/symfony/Console/blob/master/Output/StreamOutput.php#L93-112
  * @codeCoverageIgnore
  */
 public function isSupported()
 {
     if (DIRECTORY_SEPARATOR === '\\') {
         return false !== getenv('ANSICON');
     }
     return function_exists('posix_isatty') && @posix_isatty(STDOUT);
 }
Beispiel #24
0
 public function initialize()
 {
     if (DIRECTORY_SEPARATOR === '\\' && !(bool) getenv('ANSICON') && getenv('ConEmuANSI') !== 'ON' || function_exists('posix_isatty') && !posix_isatty($this->getConfig('output'))) {
         $this->setConfig("outputAs", LoggerBase::PLAIN);
     } else {
         $this->setConfig("outputAs", LoggerBase::COLOR);
     }
 }
Beispiel #25
0
 public function write($line)
 {
     if (defined('\\STDOUT') && posix_isatty(\STDOUT) && $this->_style) {
         $line = sprintf("[%sm%s", $this->_style, $line);
     }
     fwrite($this->_stream, $line);
     return $this;
 }
Beispiel #26
0
 public static function __callStatic($name, $arguments)
 {
     $color = static::$colors[$name];
     if (posix_isatty(STDOUT)) {
         return $color . $arguments[0] . static::$colors['reset'];
     }
     return $arguments[0];
 }
Beispiel #27
0
 /**
  * Is terminal interactive
  * @return bool
  */
 public static function isAtty()
 {
     try {
         self::loadExtension('posix');
         return is_callable('posix_isatty') ? posix_isatty(STDOUT) : false;
     } catch (\Exception $Error) {
         return false;
     }
 }
Beispiel #28
0
 /**
  * Returns true if the stream supports colorization.
  *
  * Colorization is disabled if not supported by the stream:
  *
  *  -  Windows without Ansicon and ConEmu
  *  -  non tty consoles
  *
  * @return bool    true if the stream supports colorization, false otherwise
  */
 protected function hasColorSupport()
 {
     // @codeCoverageIgnoreStart
     if (DIRECTORY_SEPARATOR == '\\') {
         return false !== getenv('ANSICON') || 'ON' === getenv('ConEmuANSI');
     }
     return function_exists('posix_isatty') && @posix_isatty($this->stream);
     // @codeCoverageIgnoreEnd
 }
Beispiel #29
0
 /**
  * Denote if stream supports ANSI format
  *
  * @param stream $stream
  * @return boolean
  */
 public static function supportsFormat($stream)
 {
     $fd_type = @get_resource_type($stream);
     if ($fd_type !== 'stream') {
         throw new InvalidArgumentException('Invalid stream argument');
     }
     $supported = function_exists('posix_isatty') && @posix_isatty($stream);
     return $supported ? true : DIRECTORY_SEPARATOR === '\\' && (false !== getenv('ANSICON') || 'ON' === getenv('ConEmuANSI') || 'xterm' === getenv('TERM'));
 }
Beispiel #30
0
 /**
  * Checks whether the output of the current script is a TTY or a pipe / redirect
  *
  * Returns true if STDOUT output is being redirected to a pipe or a file; false is
  * output is being sent directly to the terminal.
  *
  * If an env variable SHELL_PIPE exists, returned result depends it's
  * value. Strings like 1, 0, yes, no, that validate to booleans are accepted.
  *
  * To enable ASCII formatting even when shell is piped, use the
  * ENV variable SHELL_PIPE=0
  *
  * @return bool
  */
 public static function isPiped()
 {
     $shellPipe = getenv('SHELL_PIPE');
     if ($shellPipe !== false) {
         return filter_var($shellPipe, FILTER_VALIDATE_BOOLEAN);
     } else {
         return function_exists('posix_isatty') && !posix_isatty(STDOUT);
     }
 }