Skip to content

Commit

Permalink
repl: change preview default in case of custom eval functions
Browse files Browse the repository at this point in the history
Custom eval functions might have a very different behavior than the
current implementation and having a preview in such case might be
confusing. This changes the preview default to `false` in case a
custom eval function is used. It is still possible to opt into using
the previews in case that's still desirable.

PR-URL: #31259
Reviewed-By: Michaël Zasso <[email protected]>
Reviewed-By: Anto Aravinth <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Gus Caplan <[email protected]>
Reviewed-By: Rich Trott <[email protected]>
Reviewed-By: James M Snell <[email protected]>
  • Loading branch information
BridgeAR authored and MylesBorins committed Jan 16, 2020
1 parent 0271457 commit b9b044b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
5 changes: 3 additions & 2 deletions doc/api/repl.md
Original file line number Diff line number Diff line change
Expand Up @@ -597,8 +597,9 @@ changes:
`SIGINT` is received, such as when `Ctrl+C` is pressed. This cannot be used
together with a custom `eval` function. **Default:** `false`.
* `preview` {boolean} Defines if the repl prints autocomplete and output
previews or not. **Default:** `true`. If `terminal` is falsy, then there are
no previews and the value of `preview` has no effect.
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.
* Returns: {repl.REPLServer}

The `repl.start()` method creates and starts a [`repl.REPLServer`][] instance.
Expand Down
3 changes: 2 additions & 1 deletion lib/repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,9 @@ function REPLServer(prompt,
}
}

// TODO(devsnek): Add a test case for custom eval functions.
const preview = options.terminal &&
(options.preview !== undefined ? !!options.preview : true);
(options.preview !== undefined ? !!options.preview : !eval_);

this.inputStream = options.input;
this.outputStream = options.output;
Expand Down

0 comments on commit b9b044b

Please sign in to comment.