Skip to content

Commit

Permalink
Extended syntax colours with switch for win / other
Browse files Browse the repository at this point in the history
  • Loading branch information
martinheidegger committed Jan 31, 2016
1 parent d0012a7 commit 69b4dbe
Show file tree
Hide file tree
Showing 3 changed files with 171 additions and 13 deletions.
3 changes: 2 additions & 1 deletion lib/msee.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ var xtend = require('xtend');
var color = require('./color');
var table = require('text-table');
var chalk = require('chalk');
var os = require('os');

var defaultOptions = {
collapseNewlines: true,
Expand All @@ -19,7 +20,7 @@ var defaultOptions = {
codeStart: '\n',
codeEnd: '\n\n',
codePad: ' ',
codeTheme: require('./syntaxColor'),
codeTheme: os.platform() === 'win32' ? require('./syntaxColor_win') : require('./syntaxColor'),
blockquoteStart: '\n',
blockquoteEnd: '\n\n',
blockquoteColor: 'blockquote',
Expand Down
24 changes: 12 additions & 12 deletions lib/syntaxColor.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ module.exports = {
, 'log' : colors.blue
, 'warn' : colors.red
, 'error' : colors.red
, _default : colors.black
, _default : undefined
}

, 'Null': {
Expand Down Expand Up @@ -82,19 +82,19 @@ module.exports = {
, 'while' : undefined
, 'with' : undefined
, 'yield' : undefined
, _default : colors.black
, _default : undefined
}
, 'Punctuator': {
';': colors.black
, '.': colors.black
, ',': colors.black
';': undefined
, '.': undefined
, ',': undefined

, '{': colors.black
, '}': colors.black
, '(': colors.black
, ')': colors.black
, '[': colors.black
, ']': colors.black
, '{': undefined
, '}': undefined
, '(': undefined
, ')': undefined
, '[': undefined
, ']': undefined

, '<': undefined
, '>': undefined
Expand Down Expand Up @@ -153,5 +153,5 @@ module.exports = {
_default: colors.white
}

, _default: undefined
, _default: colors.green
};
157 changes: 157 additions & 0 deletions lib/syntaxColor_win.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
var colors = require('ansicolors');

// Change the below definitions in order to tweak the color theme.
module.exports = {

'Boolean': {
'true' : undefined
, 'false' : undefined
, _default : colors.brightYellow
}

, 'Identifier': {
'undefined' : colors.brightMagenta
, 'self' : colors.brightRed
, 'console' : undefined
, 'log' : colors.brightYellow
, 'warn' : colors.brightYellow
, 'error' : colors.brightYellow
, _default : undefined
}

, 'Null': {
_default: colors.brightMagenta
}

, 'Numeric': {
_default: colors.brightBlue
}

, 'String': {
_default: function (s, info) {
var nextToken = info.tokens[info.tokenIndex + 1];

// show keys of object literals and json in different color
return (nextToken && nextToken.type === 'Punctuator' && nextToken.value === ':')
? colors.brightBlue(s)
: colors.brightGreen(s);
}
}

, 'Keyword': {
'break' : undefined

, 'case' : undefined
, 'catch' : undefined
, 'class' : undefined
, 'const' : undefined
, 'continue' : undefined

, 'debugger' : undefined
, 'default' : undefined
, 'delete' : undefined
, 'do' : undefined

, 'else' : undefined
, 'export' : undefined
, 'extends' : undefined

, 'finally' : undefined
, 'for' : undefined
, 'function' : colors.brightMagenta

, 'if' : undefined
, 'import' : undefined
, 'in' : undefined
, 'instanceof' : colors.brightMagenta
, 'let' : undefined
, 'new' : colors.brightRed
, 'return' : colors.brigntMagenta
, 'static' : undefined
, 'super' : undefined
, 'switch' : undefined

, 'this' : undefined
, 'throw' : undefined
, 'try' : undefined
, 'typeof' : undefined

, 'var' : colors.brightCyan
, 'void' : undefined

, 'while' : undefined
, 'with' : undefined
, 'yield' : undefined
, _default : colors.brightCyan
}
, 'Punctuator': {
';': undefined
, '.': undefined
, ',': undefined

, '{': undefined
, '}': undefined
, '(': undefined
, ')': undefined
, '[': undefined
, ']': undefined

, '<': colors.brightMagenta
, '>': colors.brightMagenta
, '+': colors.brightMagenta
, '-': colors.brightMagenta
, '*': colors.brightMagenta
, '%': colors.brightMagenta
, '&': colors.brightMagenta
, '|': colors.brightMagenta
, '^': colors.brightMagenta
, '!': colors.brightMagenta
, '~': colors.brightMagenta
, '?': colors.brightMagenta
, ':': undefined
, '=': colors.brightMagenta

, '<=': colors.brighYellow
, '>=': colors.brighYellow
, '==': colors.brighYellow
, '!=': colors.brighYellow
, '++': colors.brighYellow
, '--': colors.brighYellow
, '<<': colors.brighYellow
, '>>': colors.brighYellow
, '&&': colors.brighYellow
, '||': colors.brighYellow
, '+=': colors.brighYellow
, '-=': colors.brighYellow
, '*=': colors.brighYellow
, '%=': colors.brighYellow
, '&=': colors.brighYellow
, '|=': colors.brighYellow
, '^=': colors.brighYellow
, '/=': colors.brighYellow
, '=>': colors.brighYellow

, '===': colors.brightCyan
, '!==': colors.brightCyan
, '>>>': colors.brightCyan
, '<<=': colors.brightCyan
, '>>=': colors.brightCyan
, '...': colors.brightCyan

, '>>>=': colors.cyan

, _default: undefined
}

// line comment
, Line: {
_default: colors.white
}

/* block comment */
, Block: {
_default: colors.white
}

, _default: undefined
};

0 comments on commit 69b4dbe

Please sign in to comment.