-
-
Notifications
You must be signed in to change notification settings - Fork 34.3k
repl: add support for multiline history #57400
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
Merged
nodejs-github-bot
merged 13 commits into
nodejs:main
from
puskin:repl-multiline-history
Apr 13, 2025
Merged
Changes from 2 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
83324e0
repl: add support for multiline history
puskin 8b261ae
repl: do not use the custom parser but split lines with \r
puskin 306ee84
repl: replace ... with | and navigate multiline history with up / down
puskin 96fb156
repl: recover lines with syntax errors in history
puskin 2741258
repl: consider removeHistoryDuplicates when saving multiline history
puskin b41273a
repl: add pipe char for browsing multiline history
puskin eb931ad
repl: update the cursor logic in kGetDisplayPos instead of getCursorPos
puskin 10af9e6
fixup! simplify implementation
BridgeAR c5b0df9
fixup! simplify code further
BridgeAR 0050358
fixup! linter
BridgeAR 8f52797
repl: update to the history file, not using EOL
puskin 23f7e47
repl: use unicode chars for new lines
puskin cab0f16
repl: reverse the order of multiline histories
puskin 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,90 @@ | ||
| 'use strict'; | ||
|
|
||
| // Flags: --expose-internals | ||
|
|
||
| const common = require('../common'); | ||
|
|
||
| const assert = require('assert'); | ||
| const repl = require('internal/repl'); | ||
| const stream = require('stream'); | ||
| const fixtures = require('../common/fixtures'); | ||
|
|
||
| class ActionStream extends stream.Stream { | ||
| run(data) { | ||
| const _iter = data[Symbol.iterator](); | ||
| const doAction = () => { | ||
| const next = _iter.next(); | ||
| if (next.done) { | ||
| // Close the repl. Note that it must have a clean prompt to do so. | ||
| this.emit('keypress', '', { ctrl: true, name: 'd' }); | ||
| return; | ||
| } | ||
| const action = next.value; | ||
|
|
||
| if (typeof action === 'object') { | ||
| this.emit('keypress', '', action); | ||
| } | ||
| setImmediate(doAction); | ||
| }; | ||
| doAction(); | ||
| } | ||
| resume() {} | ||
| pause() {} | ||
| } | ||
| ActionStream.prototype.readable = true; | ||
|
|
||
| { | ||
| // Testing multiline history loading | ||
| const tmpdir = require('../common/tmpdir'); | ||
| tmpdir.refresh(); | ||
| const replHistoryPath = fixtures.path('.node_repl_history-multiline'); | ||
|
|
||
| const checkResults = common.mustSucceed((r) => { | ||
| assert.strictEqual(r.history.length, 4); | ||
|
|
||
| r.input.run([{ name: 'up' }]); | ||
| assert.strictEqual( | ||
| r.line, | ||
| 'var d = [\n' + | ||
| ' {\n' + | ||
BridgeAR marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ' a: 1,\n' + | ||
| ' b: 2,\n' + | ||
| ' },\n' + | ||
| ' {\n' + | ||
| ' a: 3,\n' + | ||
| ' b: 4,\n' + | ||
| ' c: [{ a: 1, b: 2 },\n' + | ||
| ' {\n' + | ||
| ' a: 3,\n' + | ||
| ' b: 4,\n' + | ||
| ' }\n' + | ||
| ' ]\n' + | ||
| ' }\n' + | ||
| ']' | ||
| ); | ||
|
|
||
| r.input.run([{ name: 'up' }]); | ||
| assert.strictEqual(r.line, 'const c = [\n {\n a: 1,\n b: 2,\n }\n]'); | ||
|
|
||
| r.input.run([{ name: 'up' }]); | ||
| assert.strictEqual(r.line, '`const b = [\n 1,\n 2,\n 3,\n 4,\n]`'); | ||
|
|
||
| r.input.run([{ name: 'up' }]); | ||
| assert.strictEqual(r.line, 'a = `\nI am a multiline string\nI can be as long as I want`'); | ||
|
|
||
| }); | ||
|
|
||
| repl.createInternalRepl( | ||
| { NODE_REPL_HISTORY: replHistoryPath }, | ||
| { | ||
| terminal: true, | ||
| input: new ActionStream(), | ||
| output: new stream.Writable({ | ||
| write(chunk, _, next) { | ||
| next(); | ||
| } | ||
| }), | ||
| }, | ||
| checkResults | ||
| ); | ||
| } | ||
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.
Uh oh!
There was an error while loading. Please reload this page.