-
-
Notifications
You must be signed in to change notification settings - Fork 436
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add syntax highlighting in the REPL #2254
Merged
Planeshifter
merged 23 commits into
stdlib-js:develop
from
Snehil-Shah:syntax-highlighting
May 31, 2024
Merged
Changes from 19 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
0e9f467
feat: add syntax highlighting in the REPL
Snehil-Shah ceaa8c0
fix: cache line to avoid highlighting when no change detected
Snehil-Shah c422e71
feat: explicitly define keywords like `let`
Snehil-Shah 295633f
style: stick to conventions
Snehil-Shah 5af1fa7
fix: suggestions
Snehil-Shah c4d1748
feat: add more token types
Snehil-Shah 1ebc27f
fix: add missing `return` statement
Snehil-Shah 3c19a6b
docs: change jsdoc
Snehil-Shah 1e4ea8c
fix: incorrect color name
Snehil-Shah 33eb6a0
feat: resolve local identifiers & declarations
Snehil-Shah f197dcc
docs: update jsdoc and variable names
Snehil-Shah f9ad172
feat: update control keywords
Snehil-Shah bfe7408
fix: handle edge cases
Snehil-Shah a72346a
fix: use `contains.factory`
Snehil-Shah bbd1e11
fix: variable names and using `contains.factory`
Snehil-Shah 7a94ce4
refactor: return all local nodes after resolving them
Snehil-Shah c7cd532
docs: update jsdoc
Snehil-Shah 186bbac
fix: handle reserved names
Snehil-Shah 76afa3c
fix: suggestions
Snehil-Shah 34f53d0
docs: clarify comments
Snehil-Shah 94c2e01
fix: avoid conflicts between reserved names and object properties
Snehil-Shah b2fd379
fix: detect if identifier exists before pushing a `name` token
Snehil-Shah 9e5015d
style: fix bracket spacing
Snehil-Shah File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/** | ||
* @license Apache-2.0 | ||
* | ||
* Copyright (c) 2024 The Stdlib Authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
// MAIN // | ||
|
||
/** | ||
* Table mapping generic color names to their ANSI color codes. | ||
* | ||
* @private | ||
* @name ANSI | ||
* @type {Object} | ||
*/ | ||
var ANSI = { | ||
// Original colors: | ||
'black': '\u001b[30m', | ||
'red': '\u001b[31m', | ||
'green': '\u001b[32m', | ||
'yellow': '\u001b[33m', | ||
'blue': '\u001b[34m', | ||
'magenta': '\u001b[35m', | ||
'cyan': '\u001b[36m', | ||
'white': '\u001b[37m', | ||
|
||
// Bright colors: | ||
'brightBlack': '\u001b[90m', | ||
'brightRed': '\u001b[91m', | ||
'brightGreen': '\u001b[92m', | ||
'brightYellow': '\u001b[93m', | ||
'brightBlue': '\u001b[94m', | ||
'brightMagenta': '\u001b[95m', | ||
'brightCyan': '\u001b[96m', | ||
'brightWhite': '\u001b[97m', | ||
|
||
// Reset colors: | ||
'reset': '\u001b[0m' | ||
}; | ||
|
||
|
||
// EXPORTS // | ||
|
||
module.exports = ANSI; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's get this in for now as-is, but as a follow-up it may be worthwhile to add a separate package specifically for colors, as an alternative to https://www.npmjs.com/package/colors or https://www.npmjs.com/package/chalk. Similar to what
chalk
is doing, we could do feature detection in there for which ANSI colors are supported and adjust the exports accordingly. A potential location for such a package may be@stdlib/cli/colors
, with color support detection potentially living in theassert
namespace.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That would be nice to have! will add it as a TODO.