Skip to content

Commit

Permalink
Close GH-690: Adding syntax highlighting to bower info. Fixes #571
Browse files Browse the repository at this point in the history
  • Loading branch information
Nick Heiner authored and satazor committed Aug 1, 2013
1 parent d0f9054 commit 2e615e7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
19 changes: 17 additions & 2 deletions lib/renderers/StandardRenderer.js
@@ -1,4 +1,6 @@
require('colors');
var cardinal = require('cardinal');
var cardinalColors = require('cardinal/colors');

This comment has been minimized.

Copy link
@thlorenz

thlorenz Aug 1, 2013

this breaks with cardinal@0.4.2.
do: var colors = require('ansicolors'); instead, since that is what it uses now. (npm install ansicolors first)

This comment has been minimized.

Copy link
@satazor

satazor Aug 1, 2013

Member

Yes I've updated the master branch.

This comment has been minimized.

Copy link
@satazor

satazor Aug 1, 2013

Member

Thanks!

This comment has been minimized.

Copy link
@thlorenz

thlorenz Aug 1, 2013

I hope you also saw below comment relating to this line which breaks the feature of rendering key and value strings in different colors?

var path = require('path');
var mout = require('mout');
var archy = require('archy');
Expand Down Expand Up @@ -162,14 +164,27 @@ StandardRenderer.prototype._search = function (results) {

StandardRenderer.prototype._info = function (data) {
var str;
var highlightedJson;

// If the response is the whole package info
// render the appropriate template
if (typeof data === 'object' && data.name && data.versions) {
str = template.render('std/info.std', data);
} else {
// TODO: colorize/highlight json
str = '\n' + stringifyObject(data, { indent: ' ' }) + '\n';

highlightedJson = cardinal.highlight(stringifyObject(data, { indent: ' ' }), {
theme: {
String: {
_default: cardinalColors.cyan

This comment has been minimized.

Copy link
@thlorenz

thlorenz Aug 1, 2013

If you want to keep keys looking different from values in your json either don't override this or do it similarly to this

See image here

This comment has been minimized.

Copy link
@tschaub

tschaub Aug 1, 2013

Contributor

@thlorenz - the output of stringifyObject is not JSON (keys are not quoted), it's just an object literal in this case.

This comment has been minimized.

Copy link
@satazor

satazor Aug 1, 2013

Member

stringifyObject removes quotes, but the final output still performs well in terms of making keys and values colors different.

This comment has been minimized.

Copy link
@thlorenz

thlorenz Aug 2, 2013

In the default theme the key detection is done by determining that the token after it is a ':' punctuator. That makes key coloring more robust. Overriding it like is done her breaks that.

},
Identifier: {
_default: cardinalColors.green
}
},
json: true
});

str = '\n' + highlightedJson + '\n';
}

this._write(process.stdout, str);
Expand Down
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -26,6 +26,7 @@
"bower-json": "~0.2.0",
"bower-logger": "~0.1.0",
"bower-registry-client": "~0.1.1",
"cardinal": "~0.4.0",
"chmodr": "~0.1.0",
"colors": "~0.6.0-1",
"fstream": "~0.1.22",
Expand Down

0 comments on commit 2e615e7

Please sign in to comment.