Returns true if STDOUT supports colorization.
This code has been copied and adapted from
\Symfony\Component\Console\Output\OutputStream.
@return boolean
356621
public static function isSupportColor(): bool
    {
        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')// || 'cygwin' === getenv('TERM')
                ;
        }

        if (!\defined('STDOUT')) {
            return false;
        }

        return self::isInteractive(STDOUT);
    }
878020
public function isTerminalType()
    {
        if(!$this->hasValidResource()) {
            return false;
        }

        if (function_exists('stream_isatty')) {
            /** @noinspection PhpVoidFunctionResultUsedInspection */
            return (bool)stream_isatty($this->resource);
        }

        return false;
    }
576420
protected function color(&$out)
    {
        $color = [Type::T_COLOR];

        if ($this->match('(#([0-9a-f]{6})|#([0-9a-f]{3}))', $m)) {
            if (isset($m[3])) {
                $num = hexdec($m[3]);

                foreach ([3, 2, 1] as $i) {
                    $t = $num & 0xf;
                    $color[$i] = $t << 4 | $t;
                    $num >>= 4;
                }
            } else {
                $num = hexdec($m[2]);

                foreach ([3, 2, 1] as $i) {
                    $color[$i] = $num & 0xff;
                    $num >>= 8;
                }
            }

            $out = $color;

            return true;
        }

        return false;
    }
382506
protected function isNextLineIndented()
  {
    $currentIndentation = $this->getCurrentLineIndentation();
    $notEOF = $this->moveToNextLine();

    while ($notEOF && $this->isCurrentLineEmpty()) {
      $notEOF = $this->moveToNextLine();
    }

    if (false === $notEOF) {
      return false;
    }

    $ret = false;
    if ($this->getCurrentLineIndentation() <= $currentIndentation) {
      $ret = true;
    }

    $this->moveToPreviousLine();

    return $ret;
  }
32692
public function isSupported()
    {
        $mixer   = $this->getMixer();
        $request = $mixer->getRequest();

        // Support HTML GET requests and also form submits (so we can render errors on POST)
        if(($request->isFormSubmit() || $request->isGet()) && $request->getFormat() == 'html' && !$request->isAjax()) {
            return parent::isSupported();
        }

        return false;
    }
250958
private function hasTty()
    {
        if (! $this->output instanceof StreamOutput) {
            return false;
        }

        if (getenv("PERIDOT_TTY")) {
            return true;
        }

        return $this->isTtyTerminal($this->output);
    }
1130242
private function resultCallHasOutput()
    {
        if (!$this->result instanceof ExecutedStepResult) {
            return false;
        }

        return $this->result->getCallResult()->hasStdOut() || $this->result->getCallResult()->hasException();
    }
370043
protected static function hasNiceSupport()
    {
        exec("nice 2>&1", $niceOutput);

        if (is_array($niceOutput) && isset($niceOutput[0])) {
            if (preg_match('/usage/', $niceOutput[0]) || (preg_match('/^\d+$/', $niceOutput[0]))) {
                /*
                 * Nice is available - default niceness (+10)
                 * https://www.lifewire.com/uses-of-commands-nice-renice-2201087
                 * https://www.computerhope.com/unix/unice.htm
                 */

                return true;
            }
            return false;
        }
    }
180244
public static function out($message, $colour = false, $output = 'STDOUT')
    {
        if (array_key_exists($output, self::$outputs)) {
            $output = self::$outputs[$output];
        }

        if ($colour) {
            file_put_contents($output, Colours::string($message, $colour).self::$eol, FILE_APPEND);
        } else {
            file_put_contents($output, $message.self::$eol, FILE_APPEND);
        }
    }
164140
public function output()
    {
        if ($this->_output) {
            return;
        }
        if ($this->getFormat() === 'html') {
            $this->outputHtml();
        } else {
            $this->outputPlaintext();
        }
        $this->_output = true;
    }
156323
public function run(): bool
    {
        foreach ($this->collectTestDefinitions() as $key => $testDefinitionCollection) {
            if (count($testDefinitionCollection) > 0) {
                $this->printer->println(
                    $this->printer->colorize(
                        PrinterInterface::CYAN_BACKGROUND . PrinterInterface::WHITE,
                        $this->printGroupHeaderForKeyAndDefinition($key, reset($testDefinitionCollection))
                    )
                );
                /** @var DefinitionInterface $testDefinition */
                foreach ($testDefinitionCollection as $testDefinition) {
                    $this->printer->println($testDefinition->getDescription());
                }
            }
        }

        return true;
    }
969723
protected function showHelp()
    {
        $this->log('Usage:', 'yellow');
        $this->log('  vobject [options] command [arguments]');
        $this->log('');
        $this->log('Options:', 'yellow');
        $this->log($this->colorize('green', '  -q            ')."Don't output anything.");
        $this->log($this->colorize('green', '  -help -h      ').'Display this help message.');
        $this->log($this->colorize('green', '  --format      ').'Convert to a specific format. Must be one of: vcard, vcard21,');
        $this->log($this->colorize('green', '  --forgiving   ').'Makes the parser less strict.');
        $this->log('                vcard30, vcard40, icalendar20, jcal, jcard, json, mimedir.');
        $this->log($this->colorize('green', '  --inputformat ').'If the input format cannot be guessed from the extension, it');
        $this->log('                must be specified here.');
        // Only PHP 5.4 and up
        if (version_compare(PHP_VERSION, '5.4.0') >= 0) {
            $this->log($this->colorize('green', '  --pretty      ').'json pretty-print.');
        }
        $this->log('');
        $this->log('Commands:', 'yellow');
        $this->log($this->colorize('green', '  validate').' source_file              Validates a file for correctness.');
        $this->log($this->colorize('green', '  repair').' source_file [output_file]  Repairs a file.');
        $this->log($this->colorize('green', '  convert').' source_file [output_file] Converts a file.');
        $this->log($this->colorize('green', '  color').' source_file                 Colorize a file, useful for debbugging.');
        $this->log(
        <<<HELP

If source_file is set as '-', STDIN will be used.
If output_file is omitted, STDOUT will be used.
All other output is sent to STDERR.

HELP
        );

        $this->log('Examples:', 'yellow');
        $this->log('   vobject convert contact.vcf contact.json');
        $this->log('   vobject convert --format=vcard40 old.vcf new.vcf');
        $this->log('   vobject convert --inputformat=json --format=mimedir - -');
        $this->log('   vobject color calendar.ics');
        $this->log('');
        $this->log('https://github.com/fruux/sabre-vobject', 'purple');
    }
573612
function checkColorize() {
	if (defaultColorizeArg !== undefined) {
		return defaultColorizeArg;
	}
	// default is to only colorize if we have a TTY and not running on TTY
	defaultColorizeArg = process.stdout.isTTY && !process.env.TRAVIS;
	for (let c = 1; c < process.argv.length; c++) {
		const arg = process.argv[c];
		if (arg === '--colorize' || arg === '--color' || arg === '--colors') {
			defaultColorizeArg = true;
			break;
		} else if (arg === '--no-colors' || arg === '--no-color') {
			defaultColorizeArg = false;
			break;
		}
	}
	return defaultColorizeArg;
}
1322929
public function stream_flush()
    {
        if (!$this->getResource()) {
            return false;
        }

        $buffer = $this->getDataBuffer();
        $bufferWritten = $buffer;
        $retVal = true;
        if (!empty($buffer)) {

            $object = $this->getResource()->getObject();
            $mimetype = $this->getService()->guessFileType($this->getResource()->getResourceName());
            $object->content_type = $mimetype;
            $object->setData($buffer);
            $object->Create();
        }

       if (strlen($bufferWritten) ==  strlen($buffer)) {
            $this->setDataBuffer(null);
        } else {
            $this->setDataBuffer($buffer);
        }
        $this->setDataBuffer(null);

        return $retVal;
    }
309423
protected static function is_current_output_buffer() : bool {
        if (empty(self::$taskloginfo)) {
            return false;
        }

        if ($ob = ob_get_status()) {
            return 'core\\task\\logmanager::add_line' == $ob['name'];
        }

        return false;
    }
388855
def has_colors(stream):
    
    if not hasattr(stream, "isatty"):
        return False
    if not stream.isatty():
        return False  # auto color only on TTYs
    try:
        import curses
        curses.setupterm()
        return curses.tigetnum("colors") > 2
    except:
        return False
1184975
def printcolour(text, sameline=False, colour=get_colour("ENDC")):
    
    if sameline:
        sep = ''
    else:
        sep = '\n'
    sys.stdout.write(get_colour(colour) + text + bcolours["ENDC"] + sep)