Skip to content
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

repl: small improvements #26240

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 18 additions & 11 deletions lib/repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,7 @@ function REPLServer(prompt,
sawSIGINT = false;
return;
}
self.output.write('(To exit, press ^C again or type .exit)\n');
self.output.write('(To exit, press ^C again or ^D or type .exit)\n');
sawSIGINT = true;
} else {
sawSIGINT = false;
Expand Down Expand Up @@ -700,6 +700,11 @@ function REPLServer(prompt,
return;
}
if (!self.editorMode || !self.terminal) {
// Before exiting, make sure to clear the line.
if (key.ctrl && key.name === 'd' &&
self.cursor === 0 && self.line.length === 0) {
self.clearLine();
}
ttyWrite(d, key);
return;
}
Expand Down Expand Up @@ -1430,6 +1435,8 @@ function defineDefaultCommands(repl) {
var line = `.${name}${cmd.help ? spaces + cmd.help : ''}\n`;
this.outputStream.write(line);
}
this.outputStream.write('\nPress ^C to abort current expression, ' +
'^D to exit the repl\n');
this.displayPrompt();
}
});
Expand Down Expand Up @@ -1472,16 +1479,16 @@ function defineDefaultCommands(repl) {
this.displayPrompt();
}
});

repl.defineCommand('editor', {
help: 'Enter editor mode',
action() {
if (!this.terminal) return;
_turnOnEditorMode(this);
this.outputStream.write(
'// Entering editor mode (^D to finish, ^C to cancel)\n');
}
});
if (repl.terminal) {
repl.defineCommand('editor', {
help: 'Enter editor mode',
action() {
_turnOnEditorMode(this);
this.outputStream.write(
'// Entering editor mode (^D to finish, ^C to cancel)\n');
}
});
}
}

function regexpEscape(s) {
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-repl-editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ function run({ input, output, event, checkTerminalCodes = true }) {
const tests = [
{
input: '',
output: '\n(To exit, press ^C again or type .exit)',
output: '\n(To exit, press ^C again or ^D or type .exit)',
event: { ctrl: true, name: 'c' }
},
{
Expand Down
4 changes: 2 additions & 2 deletions test/parallel/test-repl-save-load.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ assert.strictEqual(fs.readFileSync(saveFileName, 'utf8'),
'}'
];
const putIn = new ArrayStream();
const replServer = repl.start('', putIn);
const replServer = repl.start({ terminal: true, stream: putIn });

putIn.run(['.editor']);
putIn.run(cmds);
Expand All @@ -70,7 +70,7 @@ assert.strictEqual(fs.readFileSync(saveFileName, 'utf8'),
putIn.run([`.save ${saveFileName}`]);
replServer.close();
assert.strictEqual(fs.readFileSync(saveFileName, 'utf8'),
`${cmds.join('\n')}\n`);
`${cmds.join('\n')}\n\n`);
}

// make sure that the REPL data is "correct"
Expand Down
3 changes: 2 additions & 1 deletion test/parallel/test-repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -439,11 +439,12 @@ const errorTests = [
expect: [
/\.break/,
/\.clear/,
/\.editor/,
/\.exit/,
/\.help/,
/\.load/,
/\.save/,
'',
'Press ^C to abort current expression, ^D to exit the repl',
/'thefourtheye'/
]
},
Expand Down