Skip to content

Commit

Permalink
repl: standardize Control key indications
Browse files Browse the repository at this point in the history
Throughout our messages and docs, we refer to the Control key in a
surprisingly varied number of ways:

* Control
* Ctrl
* Cntl
* varied capitalization on the above (e.g., ctrl vs. Ctrl)

Then, in key combinations:

* One of the items from the previous list followed by `-`
* ... or followed by `+`
* ... surrounded or not by `<` and `>`
* ... and inside backticks or not
* ... or just `^`

This is the start of standardization on the formulation recommended by
the Microsoft Style Guide (e.g., **Ctrl+C**).

PR-URL: #35270
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
  • Loading branch information
Trott committed Sep 28, 2020
1 parent 6fc3b0d commit eec4a5b
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 24 deletions.
24 changes: 12 additions & 12 deletions doc/api/repl.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ feature set.

The following special commands are supported by all REPL instances:

* `.break`: When in the process of inputting a multi-line expression, entering
the `.break` command (or pressing the `<ctrl>-C` key combination) will abort
* `.break`: When in the process of inputting a multi-line expression, enter
the `.break` command (or press **Ctrl+C**) to abort
further input or processing of that expression.
* `.clear`: Resets the REPL `context` to an empty object and clears any
multi-line expression being input.
Expand All @@ -45,7 +45,7 @@ The following special commands are supported by all REPL instances:
`> .save ./file/to/save.js`
* `.load`: Load a file into the current REPL session.
`> .load ./file/to/load.js`
* `.editor`: Enter editor mode (`<ctrl>-D` to finish, `<ctrl>-C` to cancel).
* `.editor`: Enter editor mode (**Ctrl+D** to finish, **Ctrl+C** to cancel).

```console
> .editor
Expand All @@ -63,10 +63,10 @@ welcome('Node.js User');

The following key combinations in the REPL have these special effects:

* `<ctrl>-C`: When pressed once, has the same effect as the `.break` command.
* **Ctrl+C**: When pressed once, has the same effect as the `.break` command.
When pressed twice on a blank line, has the same effect as the `.exit`
command.
* `<ctrl>-D`: Has the same effect as the `.exit` command.
* **Ctrl+D**: Has the same effect as the `.exit` command.
* `<tab>`: When pressed on a blank line, displays global and local (scope)
variables. When pressed while entering other input, displays relevant
autocompletion options.
Expand Down Expand Up @@ -248,14 +248,14 @@ added:
-->

The REPL supports bi-directional reverse-i-search similar to [ZSH][]. It is
triggered with `<ctrl> + R` to search backward and `<ctrl> + S` to search
forward.
triggered with **Ctrl+R** to search backward and **Ctrl+S** to search
forwards.

Duplicated history entires will be skipped.

Entries are accepted as soon as any button is pressed that doesn't correspond
with the reverse search. Cancelling is possible by pressing `escape` or
`<ctrl> + C`.
with the reverse search. Cancelling is possible by pressing **Esc** or
**Ctrl+C**.

Changing the direction immediately searches for the next entry in the expected
direction from the current position on.
Expand Down Expand Up @@ -284,7 +284,7 @@ repl.start({ prompt: '> ', eval: myEval });

#### Recoverable errors

As a user is typing input into the REPL prompt, pressing the `<enter>` key will
As a user is typing input into the REPL prompt, pressing **Enter** will
send the current line of input to the `eval` function. In order to support
multi-line input, the eval function can return an instance of `repl.Recoverable`
to the provided callback function:
Expand Down Expand Up @@ -381,8 +381,8 @@ added: v0.7.7
-->

The `'exit'` event is emitted when the REPL is exited either by receiving the
`.exit` command as input, the user pressing `<ctrl>-C` twice to signal `SIGINT`,
or by pressing `<ctrl>-D` to signal `'end'` on the input stream. The listener
`.exit` command as input, the user pressing **Ctrl+C** twice to signal `SIGINT`,
or by pressing **Ctrl+D** to signal `'end'` on the input stream. The listener
callback is invoked without any arguments.

```js
Expand Down
14 changes: 8 additions & 6 deletions lib/repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -726,7 +726,9 @@ function REPLServer(prompt,
sawSIGINT = false;
return;
}
self.output.write('(To exit, press ^C again or ^D or type .exit)\n');
self.output.write(
'(To exit, press Ctrl+C again or Ctrl+D or type .exit)\n'
);
sawSIGINT = true;
} else {
sawSIGINT = false;
Expand Down Expand Up @@ -791,7 +793,7 @@ function REPLServer(prompt,
if (e && !self[kBufferedCommandSymbol] && cmd.trim().startsWith('npm ')) {
self.output.write('npm should be run outside of the ' +
'Node.js REPL, in your normal shell.\n' +
'(Press Control-D to exit.)\n');
'(Press Ctrl+D to exit.)\n');
self.displayPrompt();
return;
}
Expand Down Expand Up @@ -836,7 +838,7 @@ function REPLServer(prompt,
if (self.editorMode) {
self.output.write(`${self._initialPrompt}.editor\n`);
self.output.write(
'// Entering editor mode (^D to finish, ^C to cancel)\n');
'// Entering editor mode (Ctrl+D to finish, Ctrl+C to cancel)\n');
self.output.write(`${self[kBufferedCommandSymbol]}\n`);
self.prompt(true);
} else {
Expand Down Expand Up @@ -1508,8 +1510,8 @@ function defineDefaultCommands(repl) {
const line = `.${name}${cmd.help ? spaces + cmd.help : ''}\n`;
this.output.write(line);
}
this.output.write('\nPress ^C to abort current expression, ' +
'^D to exit the REPL\n');
this.output.write('\nPress Ctrl+C to abort current expression, ' +
'Ctrl+D to exit the REPL\n');
this.displayPrompt();
}
});
Expand Down Expand Up @@ -1555,7 +1557,7 @@ function defineDefaultCommands(repl) {
action() {
_turnOnEditorMode(this);
this.output.write(
'// Entering editor mode (^D to finish, ^C to cancel)\n');
'// Entering editor mode (Ctrl+D to finish, Ctrl+C to cancel)\n');
}
});
}
Expand Down
9 changes: 5 additions & 4 deletions test/parallel/test-repl-editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ function run({ input, output, event, checkTerminalCodes = true }) {

stream.write = (msg) => found += msg.replace('\r', '');

let expected = `${terminalCode}.editor\n` +
'// Entering editor mode (^D to finish, ^C to cancel)\n' +
`${input}${output}\n${terminalCode}`;
let expected =
`${terminalCode}.editor\n` +
'// Entering editor mode (Ctrl+D to finish, Ctrl+C to cancel)\n' +
`${input}${output}\n${terminalCode}`;

const replServer = repl.start({
prompt: '> ',
Expand All @@ -47,7 +48,7 @@ function run({ input, output, event, checkTerminalCodes = true }) {
const tests = [
{
input: '',
output: '\n(To exit, press ^C again or ^D or type .exit)',
output: '\n(To exit, press Ctrl+C again or Ctrl+D or type .exit)',
event: { ctrl: true, name: 'c' }
},
{
Expand Down
4 changes: 2 additions & 2 deletions test/parallel/test-repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ const errorTests = [
send: 'npm install foobar',
expect: [
'npm should be run outside of the Node.js REPL, in your normal shell.',
'(Press Control-D to exit.)'
'(Press Ctrl+D to exit.)'
]
},
{
Expand Down Expand Up @@ -453,7 +453,7 @@ const errorTests = [
/\.load/,
/\.save/,
'',
'Press ^C to abort current expression, ^D to exit the REPL',
'Press Ctrl+C to abort current expression, Ctrl+D to exit the REPL',
/'thefourtheye'/
]
},
Expand Down

0 comments on commit eec4a5b

Please sign in to comment.