Skip to content

Commit

Permalink
added extra features to repl.js
Browse files Browse the repository at this point in the history
added more detailed help messages and added a 'helpC' command
  • Loading branch information
ionicmc-rs committed Dec 19, 2023
1 parent 8d7201f commit 95caf0a
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions lib/repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -1781,12 +1781,23 @@ function defineDefaultCommands(repl) {
const line = `.${name}${cmd.help ? spaces + cmd.help : ''}\n`;
this.output.write(line);
});
this.output.write('\n in the Node.js REPL you may write regular JavaScript code\nand use REPL commands, the REPL commands are listed above\n')
this.output.write('\nPress Ctrl+C to abort current expression, ' +
'Ctrl+D to exit the REPL\n');
this.displayPrompt();
},
});

repl.defineCommand('helpC', {
help: 'get help for a specific command',
action: function(cmd) {
if(this.commands[cmd]) {
this.output.write(cmd.help);
} else {
this.output.write('Command not found');
}
this.displayPrompt();
}
})
repl.defineCommand('save', {
help: 'Save all evaluated commands in this REPL session to a file',
action: function(file) {
Expand All @@ -1801,7 +1812,7 @@ function defineDefaultCommands(repl) {
});

repl.defineCommand('load', {
help: 'Load JS from a file into the REPL session',
help: 'Load JS (variables, functions, etc) from a file into the REPL session',
action: function(file) {
try {
const stats = fs.statSync(file);
Expand All @@ -1826,7 +1837,7 @@ function defineDefaultCommands(repl) {
});
if (repl.terminal) {
repl.defineCommand('editor', {
help: 'Enter editor mode',
help: 'Enter editor mode (JS)',
action() {
_turnOnEditorMode(this);
this.output.write(
Expand Down

0 comments on commit 95caf0a

Please sign in to comment.