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

lib: repl for #14022 && readline fix debug warning #14494

Closed
wants to merge 4 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
3 changes: 2 additions & 1 deletion lib/readline.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
'use strict';

const errors = require('internal/errors');
const { debug, inherits } = require('util');
const { debuglog, inherits } = require('util');
const debug = debuglog('readline');
const { Buffer } = require('buffer');
const EventEmitter = require('events');
const { StringDecoder } = require('string_decoder');
Expand Down
28 changes: 28 additions & 0 deletions lib/repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -1267,6 +1267,34 @@ function defineDefaultCommands(repl) {
'// Entering editor mode (^D to finish, ^C to cancel)\n');
}
});

repl.defineCommand('load-editor', {
help: 'Enter load and editor mode',
action: function(file) {
if (!this.terminal) return;
REPLServer.super_.prototype.setPrompt.call(this, '');
this.write('// Entering editor mode (^D to finish, ^C to cancel)\n');
try {
var stats = fs.statSync(file);
if (stats && stats.isFile()) {
var data = fs.readFileSync(file, 'utf8');
var lines = data.split('\n');
this.displayPrompt();
for (var n = 0; n < lines.length; n++) {
if (lines[n])
this.write(`${lines[n]}\n`);
}
this.editorMode = true;
} else {
this.outputStream.write('Failed to load:' + file +
' is not a valid file\n');
}
} catch (e) {
this.outputStream.write('Failed to load:' + file + '\n');
}
this.displayPrompt();
}
});
}

function regexpEscape(s) {
Expand Down
3 changes: 2 additions & 1 deletion test/parallel/test-repl-definecommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ r.defineCommand('say2', function() {
this.displayPrompt();
});


inputStream.write('.help\n');
assert(/\n\.say1 help for say1\n/.test(output),
assert(/\n\.say1 help for say1\n/.test(output),
'help for say1 not present');
assert(/\n\.say2\n/.test(output), 'help for say2 not present');
inputStream.write('.say1 node developer\n');
Expand Down