-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3790d52
commit c09f639
Showing
20 changed files
with
3,049 additions
and
1,897 deletions.
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,67 @@ | ||
# Experimental REPL | ||
|
||
<!--introduced_in=REPLACEME--> | ||
|
||
> Stability: 1 - Early Development | ||
<!-- source_link=lib/internal/repl/experimental/index.js --> | ||
|
||
Before diving into the details of the experimental REPL, it's essential to | ||
understand its current development stage. Being an experimental feature, its | ||
stability cannot be assured. It's accessible solely through the command-line | ||
argument `--experimental-repl`. | ||
|
||
## Overview | ||
|
||
The experimental REPL seeks to enhance the existing REPL experience by | ||
introducing innovative features such as real-time Syntax Highlighting, with | ||
plans for annotations in future iterations. It's implemented asynchronously, | ||
utilizing an ECMAScript class for its functionality. | ||
|
||
## Key Features | ||
|
||
1. **Syntax Highlighting**: Real-time syntax highlighting for improved | ||
readability and a more enriched coding environment. | ||
|
||
2. **Annotations** (Upcoming): Annotations will allow users to preview the | ||
signature of a function. | ||
|
||
## Usage | ||
|
||
To interact with the experimental REPL, initialize it using the command-line | ||
argument `--experimental-repl`. However, exercise caution as this feature is | ||
still experimental and might demonstrate unexpected behavior. | ||
|
||
## Runtime | ||
|
||
Upon launching the REPL, expect the prompt to follow this format: | ||
|
||
```console | ||
In [1]: 1+1 | ||
Out[1]: 2 | ||
``` | ||
|
||
Retrieve the output of a specific line using the command `_` followed by the | ||
line number: | ||
|
||
```console | ||
In [1]: Math.max(10, 100) | ||
Out[1]: 100 | ||
|
||
In [2]: _1 | ||
Out[2]: 100 | ||
``` | ||
|
||
For accessing the output of the last three lines, use `_`, `__`, and `___` | ||
respectively. | ||
|
||
### Known Limitations | ||
|
||
Since this REPL is experimental, several limitations are known: | ||
|
||
1. Annotations are under development. | ||
2. Cursor location isn't synchronized after multiple-line text. | ||
|
||
If you'd like to propose a solution, feel free to open a | ||
[pull request](https://github.com/nodejs/node/pulls). If you've identified an | ||
issue not listed above, open an [issue](https://github.com/nodejs/node/issues). |
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
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
Large diffs are not rendered by default.
Oops, something went wrong.
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,47 @@ | ||
'use strict'; | ||
|
||
const emphasize = require('internal/repl/experimental/deps/emphasize'); | ||
const util = require('util'); | ||
|
||
function makeStyled(color) { | ||
return (s) => `\x1b[${color[0]}m${s}\x1b[${color[1]}m`; | ||
} | ||
|
||
const sheet = { | ||
'comment': makeStyled(util.inspect.colors.grey), | ||
'quote': makeStyled(util.inspect.colors.grey), | ||
|
||
'keyword': makeStyled(util.inspect.colors.green), | ||
'addition': makeStyled(util.inspect.colors.green), | ||
|
||
'number': makeStyled(util.inspect.colors.yellow), | ||
'string': makeStyled(util.inspect.colors.green), | ||
'meta meta-string': makeStyled(util.inspect.colors.cyan), | ||
'literal': makeStyled(util.inspect.colors.cyan), | ||
'doctag': makeStyled(util.inspect.colors.cyan), | ||
'regexp': makeStyled(util.inspect.colors.cyan), | ||
|
||
'attribute': undefined, | ||
'attr': undefined, | ||
'variable': makeStyled(util.inspect.colors.yellow), | ||
'template-variable': makeStyled(util.inspect.colors.yellow), | ||
'class title': makeStyled(util.inspect.colors.yellow), | ||
'type': makeStyled(util.inspect.colors.yellow), | ||
|
||
'symbol': makeStyled(util.inspect.colors.magenta), | ||
'bullet': makeStyled(util.inspect.colors.magenta), | ||
'subst': makeStyled(util.inspect.colors.magenta), | ||
'meta': makeStyled(util.inspect.colors.magenta), | ||
'meta keyword': makeStyled(util.inspect.colors.magenta), | ||
'link': makeStyled(util.inspect.colors.magenta), | ||
|
||
'built_in': makeStyled(util.inspect.colors.cyan), | ||
'deletion': makeStyled(util.inspect.colors.red), | ||
|
||
'emphasis': makeStyled(util.inspect.colors.italic), | ||
'strong': makeStyled(util.inspect.colors.bold), | ||
'formula': makeStyled(util.inspect.colors.inverse), | ||
}; | ||
|
||
module.exports = (s) => | ||
emphasize.highlight('js', s, sheet).value; |
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,51 @@ | ||
'use strict'; | ||
|
||
const fs = require('internal/fs/promises'); | ||
const permission = require('internal/process/permission'); | ||
const path = require('path'); | ||
const os = require('os'); | ||
|
||
const { | ||
StringPrototypeSplit, | ||
} = primordials; | ||
|
||
module.exports = async () => { | ||
let handle; | ||
|
||
try { | ||
const historyPath = path.join(os.homedir(), '.node_repl_history'); | ||
if (permission.isEnabled() && permission.has('fs.write', historyPath) === false) { | ||
process.stdout.write('\nAccess to FileSystemWrite is restricted.\n' + | ||
'REPL session history will not be persisted.\n'); | ||
return { | ||
__proto__: null, | ||
history: [], | ||
writeHistory: () => false, | ||
}; | ||
} | ||
|
||
handle = await fs.open(historyPath, 'a+', 0o0600); | ||
const data = await handle.readFile({ encoding: 'utf8' }); | ||
const history = StringPrototypeSplit(data, os.EOL, 1000); | ||
const writeHistory = async (d) => { | ||
if (!handle) { | ||
return false; | ||
} | ||
try { | ||
await handle.truncate(0); | ||
await handle.writeFile(d.join(os.EOL)); | ||
return true; | ||
} catch { | ||
handle.close().catch(() => undefined); | ||
handle = null; | ||
return false; | ||
} | ||
}; | ||
return { __proto__: null, history, writeHistory }; | ||
} catch { | ||
if (handle) { | ||
handle.close().catch(() => undefined); | ||
} | ||
return { __proto__: null, history: [], writeHistory: () => false }; | ||
} | ||
}; |
Oops, something went wrong.