ORDER BY NAME
LIMIT 10
-You can enable ANSI coloring by passing the ``--colors`` option.
+
+Syntax highlighting
+===================
+ANSI colors are applied automatically when not piping; you can use the
+``--highlight`` option to override the automatism.
+
+``--highlight`` option values:
+
+``none``
+ No highlighting. Use it to disable automatic highlighting
+``ansi``
+ ANSI escape codes for your shell
+``html``
+ HTML tags
====
========
Building
========
+
+Preparation
+===========
+- Adjust version number in ``src/phpsqllint/Cli.php``
+- Adjust version number in ``build.xml``
+
+
+Create the release
+==================
You'll need `phing`__, the PHP build tool::
$ phing
protected $renderer;
protected $format = false;
- protected $colors = false;
+
+ /**
+ * What syntax highlighting mode should be used
+ *
+ * none, ansi, html
+ */
+ protected $highlight = 'none';
+
/**
* Start processing.
return false;
}
+ $typeMap = array(
+ 'none' => 'text',
+ 'ansi' => 'cli',
+ 'html' => 'html',
+ );
$options = array(
- //FIXME: automatically detect if the shell/tool supports colors
- 'type' => $this->colors ? 'cli' : 'text'
+ 'type' => $typeMap[$this->highlight],
);
echo \SqlParser\Utils\Formatter::format($sql, $options) . "\n";
}
)
);
$parser->addOption(
- 'colors',
- array(
- 'long_name' => '--color',
- 'description' => 'Use colors in formatting output',
- 'action' => 'StoreTrue',
- )
- );
- $parser->addOption(
- 'nocolors',
+ 'highlight',
array(
- 'long_name' => '--nocolor',
- 'description' => 'Disable colors in formatting output',
- 'action' => 'StoreTrue',
+ 'short_name' => '-h',
+ 'long_name' => '--highlight',
+ 'description' => 'Highlighting mode (when using --format)',
+ 'action' => 'StoreString',
+ 'choices' => array(
+ 'none',
+ 'ansi',
+ 'html',
+ 'auto',
+ ),
+ 'default' => 'auto',
+ 'add_list_option' => true,
)
);
$parser->addOption(
$this->format = $result->options['format'];
- if ($result->options['colors'] !== null) {
- $this->colors = $result->options['colors'];
- } else if ($result->options['nocolors'] !== null) {
- $this->colors = !$result->options['nocolors'];
- } else {
- //default coloring to enabled, except
- // when piping | to another tool
- $this->colors = true;
- if (function_exists('posix_isatty')
- && !posix_isatty(STDOUT)
- ) {
- $this->colors = false;
+ $this->highlight = $result->options['highlight'];
+ if ($this->highlight == 'auto') {
+ if (php_sapi_name() == 'cli') {
+ //default coloring to enabled, except
+ // when piping | to another tool
+ $this->highlight = 'ansi';
+ if (function_exists('posix_isatty')
+ && !posix_isatty(STDOUT)
+ ) {
+ $this->highlight = 'none';
+ }
+ } else {
+ //no idea where we are, so do not highlight
+ $this->highlight = 'none';
}
}