-
Notifications
You must be signed in to change notification settings - Fork 30.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
```js > node > .editor // Entering editor mode (^D to finish, ^C to cancel) function test() { console.log('tested!'); } test(); // ^D tested! undefined > ``` PR-URL: #7275 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Evan Lucas <evanlucas@me.com>
- Loading branch information
1 parent
769f63c
commit b779eb4
Showing
4 changed files
with
206 additions
and
3 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
const assert = require('assert'); | ||
const repl = require('repl'); | ||
|
||
// \u001b[1G - Moves the cursor to 1st column | ||
// \u001b[0J - Clear screen | ||
// \u001b[3G - Moves the cursor to 3rd column | ||
const terminalCode = '\u001b[1G\u001b[0J> \u001b[3G'; | ||
|
||
function run(input, output, event) { | ||
const stream = new common.ArrayStream(); | ||
let found = ''; | ||
|
||
stream.write = (msg) => found += msg.replace('\r', ''); | ||
|
||
const expected = `${terminalCode}.editor\n` + | ||
'// Entering editor mode (^D to finish, ^C to cancel)\n' + | ||
`${input}${output}\n${terminalCode}`; | ||
|
||
const replServer = repl.start({ | ||
prompt: '> ', | ||
terminal: true, | ||
input: stream, | ||
output: stream, | ||
useColors: false | ||
}); | ||
|
||
stream.emit('data', '.editor\n'); | ||
stream.emit('data', input); | ||
replServer.write('', event); | ||
replServer.close(); | ||
assert.strictEqual(found, expected); | ||
} | ||
|
||
const tests = [ | ||
{ | ||
input: '', | ||
output: '\n(To exit, press ^C again or type .exit)', | ||
event: {ctrl: true, name: 'c'} | ||
}, | ||
{ | ||
input: 'var i = 1;', | ||
output: '', | ||
event: {ctrl: true, name: 'c'} | ||
}, | ||
{ | ||
input: 'var i = 1;\ni + 3', | ||
output: '\n4', | ||
event: {ctrl: true, name: 'd'} | ||
} | ||
]; | ||
|
||
tests.forEach(({input, output, event}) => run(input, output, event)); |
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