Skip to content
Open
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
68 changes: 67 additions & 1 deletion doc/api/repl.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ result. Input and output may be from `stdin` and `stdout`, respectively, or may
be connected to any Node.js [stream][].

Instances of [`repl.REPLServer`][] support automatic completion of inputs,
completion preview, simplistic Emacs-style line editing, multi-line inputs,
completion preview, inline syntax highlighting, automatic indentation,
function signature hints, simplistic Emacs-style line editing, multi-line inputs,
[ZSH][]-like reverse-i-search, [ZSH][]-like substring-based history search,
ANSI-styled output, saving and restoring current REPL session state, error
recovery, and customizable evaluation functions. Terminals that do not support
Expand Down Expand Up @@ -439,6 +440,65 @@ function myWriter(output) {
}
```

### Syntax highlighting

<!-- YAML
added: REPLACEME
-->

> Stability: 1 - Experimental

> [!IMPORTANT]
> These features require the `--experimental-repl-enhancements` flag.

```bash
node --experimental-repl-enhancements
```

When the flag is enabled and `useColors` is `true`, the REPL highlights
JavaScript input using the following color scheme:

* **Keywords** (`const`, `let`, `function`, `if`, `return`, etc.): Magenta
* **Strings** (single-quoted, double-quoted, and template literals): Green
* **Numbers**: Yellow
* **Boolean literals** (`true`, `false`), `null`, `undefined`, `NaN`,
`Infinity`: Yellow
* **Regular expressions**: Red
* **Comments** (line and block): Gray

Syntax highlighting is applied only to the display; the internal `line`
property remains plain text. Highlighting can be disabled by passing
`syntaxHighlighting: false` to [`repl.start()`][].

### Auto-indentation

<!-- YAML
added: REPLACEME
-->

> Stability: 1 - Experimental

When the `--experimental-repl-enhancements` flag is enabled and entering
multi-line input (e.g., a function body or an object literal), the REPL
automatically indents continuation lines based on the current nesting
depth of braces (`{}`), brackets (`[]`), and parentheses (`()`). The REPL
uses 2-space indentation following the Node.js coding convention.

### Function signature hints

<!-- YAML
added: REPLACEME
-->

> Stability: 1 - Experimental

When the `--experimental-repl-enhancements` flag is enabled and the user
types a function name followed by `(`, the REPL displays the function's
parameter list as a dimmed hint below the input line. This uses the V8
inspector protocol to safely extract function signatures without side
effects. Signature hints require the `preview` option to be enabled and
the inspector to be available.

## Class: `REPLServer`

<!-- YAML
Expand Down Expand Up @@ -791,6 +851,12 @@ changes:
previews or not. **Default:** `true` with the default eval function and
`false` in case a custom eval function is used. If `terminal` is falsy, then
there are no previews and the value of `preview` has no effect.
* `syntaxHighlighting` {boolean} If `true`, enables inline syntax
highlighting of REPL input using ANSI color codes. Keywords are displayed
in magenta, strings in green, numbers in yellow, regular expressions in
red, and comments in gray. Requires `--experimental-repl-enhancements`,
`useColors` to be `true`, and `terminal` to be `true`.
**Default:** `true` when `--experimental-repl-enhancements` is set.
* `handleError` {Function} This function customizes error handling in the REPL.
It receives the thrown exception as its first argument and must return one
of the following values synchronously:
Expand Down
Loading
Loading