Permalink
Browse files

Improved terminal detection

  • Loading branch information...
1 parent 2c21d0f commit ccf28126aff1adcac8dda0942b2637729a613474 @kukulich kukulich committed Oct 2, 2012
Showing with 28 additions and 6 deletions.
  1. +1 −1 ApiGen/Application.php
  2. +1 −1 ApiGen/Config/Extension/ConfigExtension.php
  3. +24 −2 ApiGen/Environment.php
  4. +1 −1 README.md
  5. +1 −1 apigen.neon.example
View
@@ -273,7 +273,7 @@ protected function printHelp()
--plugin-config <file> Plugin config file (can be used multiple times)
--quiet <yes|no> Don't display scaning and generating messages, default "no"
--progressbar <yes|no> Display progressbars, default "yes"
- --colors <yes|no> Use colors, default "no" on Windows, "yes" on other systems
+ --colors <yes|no> Use colors, default "yes" in terminals with colors support
--update-check <yes|no> Check for update, default "yes"
--debug <yes|no> Display additional information in case of an error, default "no"
--help|-h Display this help
@@ -112,7 +112,7 @@ public function __construct(array $arguments)
{
$this->arguments = $arguments;
- $this->defaultConfig['colors'] = 'WIN' === substr(PHP_OS, 0, 3) ? FALSE : (function_exists('posix_isatty') && defined('STDOUT') ? posix_isatty(STDOUT) : TRUE);
+ $this->defaultConfig['colors'] = Environment::isTerminalWithColors();
$this->defaultConfig['templateConfig'] = Environment::getRootDir() . '/templates/' . Helper::DEFAULT_TEMPLATE_CONFIG_FILENAME;
}
View
@@ -13,8 +13,6 @@
namespace ApiGen;
-use Nette\Utils\LimitedScope;
-
/**
* ApiGen environment helpers.
*/
@@ -169,4 +167,28 @@ public static function isGitRepository()
{
return is_file(__DIR__ . '/../.gitmodules');
}
+
+ /**
+ * Returns if ApiGen is runnning on Windows.
+ *
+ * @return boolean
+ */
+ public static function isWindows()
+ {
+ return 'WIN' === substr(PHP_OS, 0, 3);
+ }
+
+ /**
+ * Returns if ApiGen is running in a terminal with colors support.
+ *
+ * @return boolean
+ */
+ public static function isTerminalWithColors()
+ {
+ if (static::isWindows()) {
+ return false !== getenv('ANSICON');
+ } else {
+ return function_exists('posix_isatty') && defined('STDOUT') && @posix_isatty(STDOUT);
+ }
+ }
}
View
@@ -219,7 +219,7 @@ Display progressbars, default is "Yes".
```--colors <yes|no>```
-Use colors, default "No" on Windows, "Yes" on other systems. Windows doesn't support colors in console however you can enable it with [Ansicon](http://adoxa.110mb.com/ansicon/).
+Use colors, default "Yes" in terminals with colors support. Windows doesn't support colors in console however you can enable it with [Ansicon](http://adoxa.110mb.com/ansicon/).
```--update-check <yes|no>```
View
@@ -60,7 +60,7 @@ quiet: No
# Display progressbars
progressbar: Yes
# Use colors
-colors: No
+colors: Yes
# Check for update
updateCheck: Yes
# Display additional information in case of an error

0 comments on commit ccf2812

Please sign in to comment.