Skip to content

Commit

Permalink
Auto-generated commit
Browse files Browse the repository at this point in the history
  • Loading branch information
stdlib-bot committed Jun 10, 2024
1 parent f5b3b94 commit f0c351b
Show file tree
Hide file tree
Showing 4 changed files with 198 additions and 18 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<section class="release" id="unreleased">

## Unreleased (2024-06-09)
## Unreleased (2024-06-10)

<section class="packages">

Expand All @@ -20,6 +20,7 @@

##### Features

- [`0856277`](https://github.com/stdlib-js/stdlib/commit/0856277523259bf111501ff87d54104b361b0fa3) - add combined styles and inbuilt syntax highlighting themes in the REPL
- [`b4c12b7`](https://github.com/stdlib-js/stdlib/commit/b4c12b7c4a76cfa71164d1b01fcbfca0426abbb3) - add APIs, commands, and tests for REPL syntax-highlighting [(#2291)](https://github.com/stdlib-js/stdlib/pull/2291)
- [`24f4a8f`](https://github.com/stdlib-js/stdlib/commit/24f4a8f24c08dd25686afc4cfb78be2e0045e844) - add syntax highlighting in the REPL
- [`0f9acd1`](https://github.com/stdlib-js/stdlib/commit/0f9acd17de012dfe755c98b602d6bb3dbe1e8117) - add `BooleanArray` to namespace
Expand Down Expand Up @@ -257,6 +258,7 @@ A total of 10 people contributed to this release. Thank you to the following con

<details>

- [`0856277`](https://github.com/stdlib-js/stdlib/commit/0856277523259bf111501ff87d54104b361b0fa3) - **feat:** add combined styles and inbuilt syntax highlighting themes in the REPL _(by Snehil Shah)_
- [`9f3dcaf`](https://github.com/stdlib-js/stdlib/commit/9f3dcaf4d19fde9e7066f7dc12a49cf87e6fd0f7) - **fix:** update error message _(by Athan Reines)_
- [`b4c12b7`](https://github.com/stdlib-js/stdlib/commit/b4c12b7c4a76cfa71164d1b01fcbfca0426abbb3) - **feat:** add APIs, commands, and tests for REPL syntax-highlighting [(#2291)](https://github.com/stdlib-js/stdlib/pull/2291) _(by Snehil Shah, Athan Reines)_
- [`f85ed2a`](https://github.com/stdlib-js/stdlib/commit/f85ed2aafc393cfbac360ad14b97af0ee28d450b) - **docs:** update REPL namespace documentation [(#2313)](https://github.com/stdlib-js/stdlib/pull/2313) _(by stdlib-bot, Athan Reines)_
Expand Down
27 changes: 27 additions & 0 deletions lib/ansi_colors.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,33 @@ var ANSI = {
'brightCyan': '\u001b[96m',
'brightWhite': '\u001b[97m',

// Background colors:
'bgBlack': '\u001b[40m',
'bgRed': '\u001b[41m',
'bgGreen': '\u001b[42m',
'bgYellow': '\u001b[43m',
'bgBlue': '\u001b[44m',
'bgMagenta': '\u001b[45m',
'bgCyan': '\u001b[46m',
'bgWhite': '\u001b[47m',

// Bright background colors:
'bgBrightBlack': '\u001b[100m',
'bgBrightRed': '\u001b[101m',
'bgBrightGreen': '\u001b[102m',
'bgBrightYellow': '\u001b[103m',
'bgBrightBlue': '\u001b[104m',
'bgBrightMagenta': '\u001b[105m',
'bgBrightCyan': '\u001b[106m',
'bgBrightWhite': '\u001b[107m',

// Styles:
'bold': '\u001b[1m',
'underline': '\u001b[4m',
'reversed': '\u001b[7m',
'italic': '\u001b[3m',
'strikethrough': '\u001b[9m',

// Reset colors:
'reset': '\u001b[0m'
};
Expand Down
29 changes: 18 additions & 11 deletions lib/syntax_highlighter.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,28 +115,35 @@ setNonEnumerableReadOnly( SyntaxHighlighter.prototype, '_highlightLine', functio
var highlightedLine = '';
var resetCode = ANSI[ 'reset' ];
var colorCode;
var colors = this._themes[ this._theme ];
var offset = 0;
var color;
var theme = this._themes[ this._theme ];
var token;
var i;
var j;

// Sort and traverse the tokens...
tokens.sort( tokenComparator );
for ( i = 0; i < tokens.length; i++ ) {
token = tokens[ i ];
colorCode = ANSI[ colors[ token.type ] ];

// Highlight token if it's color exists in the theme...
if ( colorCode ) {
highlightedLine += line.slice( offset, token.start ); // add text before token
highlightedLine += colorCode; // insert colorCode
highlightedLine += line.slice( token.start, token.end ); // add token
highlightedLine += resetCode; // reset color
offset = token.end;
color = theme[ token.type ];
if ( !color ) {
continue; // no color defined for the token type
}
color = color.split( ' ' ); // allow combination of styles. eg: `bold magenta`
highlightedLine += line.slice( offset, token.start ); // add text before token
for ( j = 0; j < color.length; j++ ) {
// Highlight token if it's color is supported...
colorCode = ANSI[ color[ j ] ];
if ( colorCode ) {
highlightedLine += colorCode; // insert colorCode
}
}
highlightedLine += line.slice( token.start, token.end ); // add token
highlightedLine += resetCode; // reset color
offset = token.end;
}
highlightedLine += line.slice( offset ); // add remaining text

return highlightedLine;
});

Expand Down
156 changes: 150 additions & 6 deletions lib/themes.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,28 +29,172 @@
*/
var THEMES = {
'stdlib-ansi-basic': {
// Keywords:
'control': 'brightMagenta',
'keyword': 'bold brightBlue',
'specialIdentifier': 'cyan',

// Literals:
'string': 'green',
'number': 'yellow',
'literal': 'italic brightCyan',
'regexp': 'underline brightRed',

// Identifiers:
'command': 'bold magenta',
'function': 'bold yellow',
'object': 'cyan',
'variable': null,
'name': null,

// Others:
'comment': 'brightBlack',
'punctuation': null,
'operator': null
},
'stdlib-ansi-dark': {
// Keywords:
'control': 'bold brightMagenta',
'keyword': 'green',
'specialIdentifier': 'cyan',

// Literals:
'string': 'yellow',
'number': 'brightBlue',
'literal': 'italic brightCyan',
'regexp': 'bold red',

// Identifiers:
'command': 'brightGreen',
'function': 'bold magenta',
'object': 'cyan',
'variable': null,
'name': null,

// Others:
'comment': 'bold brightBlack',
'punctuation': null,
'operator': null
},
'stdlib-ansi-light': {
// Keywords:
'control': 'magenta',
'keyword': 'blue',
'specialIdentifier': 'cyan',
'specialIdentifier': 'bold cyan',

// Literals:
'string': 'brightYellow',
'number': 'brightGreen',
'literal': 'brightBlue',
'regexp': 'red',
'string': 'yellow',
'number': 'green',
'literal': 'italic brightBlue',
'regexp': 'underline red',

// Identifiers:
'command': 'brightMagenta',
'function': 'yellow',
'object': 'brightCyan',
'object': 'bold',
'variable': null,
'name': null,

// Others:
'comment': 'brightBlack',
'punctuation': null,
'operator': null
},
'stdlib-ansi-strong': {
// Keywords:
'control': 'bold magenta',
'keyword': 'bold blue',
'specialIdentifier': 'italic cyan',

// Literals:
'string': 'bold brightGreen',
'number': 'bold brightYellow',
'literal': 'italic brightBlue',
'regexp': 'underline red',

// Identifiers:
'command': 'underline brightBlue',
'function': 'bold yellow',
'object': 'italic cyan',
'variable': 'green',
'name': null,

// Others:
'comment': 'italic brightBlack',
'punctuation': null,
'operator': null
},
'minimalist': {
// Keywords:
'control': 'underline',
'keyword': 'bold',
'specialIdentifier': 'italic',

// Literals:
'string': 'underline',
'number': 'bold',
'literal': 'italic',
'regexp': 'bold underline',

// Identifiers:
'command': 'underline bold',
'function': 'italic bold',
'object': 'italic',
'variable': null,
'name': null,

// Others:
'comment': 'italic brightBlack',
'punctuation': null,
'operator': null
},
'solarized': {
// Keywords:
'control': 'green',
'keyword': 'bold',
'specialIdentifier': 'red',

// Literals:
'string': 'cyan',
'number': 'brightMagenta',
'literal': 'brightYellow',
'regexp': 'red',

// Identifiers:
'command': 'bold magenta',
'function': 'brightBlue',
'object': 'brightRed',
'variable': 'brightBlue',
'name': null,

// Others:
'comment': 'italic brightBlack',
'punctuation': null,
'operator': 'green'
},
'monokai': {
// Keywords:
'control': 'brightRed',
'keyword': 'italic brightCyan',
'specialIdentifier': 'brightMagenta',

// Literals:
'string': 'brightYellow',
'number': 'brightBlue',
'literal': 'brightBlue',
'regexp': 'underline yellow',

// Identifiers:
'command': 'bold brightGreen',
'function': 'brightGreen',
'object': 'italic brightMagenta',
'variable': null,
'name': null,

// Others:
'comment': 'brightBlack',
'punctuation': null,
'operator': 'brightRed'
}
};

Expand Down

0 comments on commit f0c351b

Please sign in to comment.