REPLServer

@JSImport("repl", "REPLServer") @native @JSType class REPLServer extends StObject

Provides a customizable Read-Eval-Print-Loop (REPL).

Instances of repl.REPLServer will accept individual lines of user input, evaluate those according to a user-defined evaluation function, then output the 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, simplistic Emacs-style line editing, multi-line inputs, ANSI-styled output, saving and restoring current REPL session state, error recovery, and customizable evaluation functions.

Instances of repl.REPLServer are created using the repl.start() method and should not be created directly using the JavaScript new keyword.

See also
trait StObject
class Object
trait Any
class Object
trait Matchable
class Any

Value members

Concrete methods

def addListener(event: String, listener: Function1[Any, Unit]): REPLServer

events.EventEmitter

events.EventEmitter

  1. close - inherited from readline.Interface
  2. line - inherited from readline.Interface
  3. pause - inherited from readline.Interface
  4. resume - inherited from readline.Interface
  5. SIGCONT - inherited from readline.Interface
  6. SIGINT - inherited from readline.Interface
  7. SIGTSTP - inherited from readline.Interface
  8. exit
  9. reset
@JSName("addListener")
def addListener_SIGCONT(event: SIGCONT, listener: Function0[Unit]): REPLServer
@JSName("addListener")
def addListener_SIGINT(event: SIGINT, listener: Function0[Unit]): REPLServer
@JSName("addListener")
def addListener_SIGTSTP(event: SIGTSTP, listener: Function0[Unit]): REPLServer
@JSName("addListener")
def addListener_close(event: close, listener: Function0[Unit]): REPLServer
@JSName("addListener")
def addListener_exit(event: exit, listener: Function0[Unit]): REPLServer
@JSName("addListener")
def addListener_line(event: line, listener: Function1[String, Unit]): REPLServer
@JSName("addListener")
def addListener_pause(event: pause, listener: Function0[Unit]): REPLServer
@JSName("addListener")
def addListener_reset(event: reset, listener: Function1[Context, Unit]): REPLServer
@JSName("addListener")
def addListener_resume(event: resume, listener: Function0[Unit]): REPLServer

Clears any command that has been buffered but not yet executed.

Clears any command that has been buffered but not yet executed.

This method is primarily intended to be called from within the action function for commands registered using the replServer.defineCommand() method.

Since

v9.0.0

def defineCommand(keyword: String, cmd: REPLCommand): Unit
def defineCommand(keyword: String, cmd: REPLCommandAction): Unit

Used to add new .-prefixed commands to the REPL instance. Such commands are invoked by typing a . followed by the keyword.

Used to add new .-prefixed commands to the REPL instance. Such commands are invoked by typing a . followed by the keyword.

Value Params
cmd

The function to invoke when the command is processed.

keyword

The command keyword (without a leading . character).

See also
def displayPrompt(): Unit

Readies the REPL instance for input from the user, printing the configured prompt to a new line in the output and resuming the input to accept new input.

Readies the REPL instance for input from the user, printing the configured prompt to a new line in the output and resuming the input to accept new input.

When multi-line input is being entered, an ellipsis is printed rather than the 'prompt'.

This method is primarily intended to be called from within the action function for commands registered using the replServer.defineCommand() method.

Value Params
preserveCursor

When true, the cursor placement will not be reset to 0.

def displayPrompt(preserveCursor: Boolean): Unit
def emit(event: String, args: Any*): Boolean
def emit(event: Symbol, args: Any*): Boolean
@JSName("emit")
def emit_SIGCONT(event: SIGCONT): Boolean
@JSName("emit")
def emit_SIGINT(event: SIGINT): Boolean
@JSName("emit")
def emit_SIGTSTP(event: SIGTSTP): Boolean
@JSName("emit")
def emit_close(event: close): Boolean
@JSName("emit")
def emit_exit(event: exit): Boolean
@JSName("emit")
def emit_line(event: line, input: String): Boolean
@JSName("emit")
def emit_pause(event: pause): Boolean
@JSName("emit")
def emit_reset(event: reset, context: Context): Boolean
@JSName("emit")
def emit_resume(event: resume): Boolean
def eval(evalCmd: String, context: Context, file: String, cb: Function2[Error | Null, Any, Unit]): Unit

Specified in the REPL options, this is the function to be used when evaluating each given line of input. If not specified in the REPL options, this is an async wrapper for the JavaScript eval() function.

Specified in the REPL options, this is the function to be used when evaluating each given line of input. If not specified in the REPL options, this is an async wrapper for the JavaScript eval() function.

def on(event: String, listener: Function1[Any, Unit]): REPLServer
@JSName("on")
def on_SIGCONT(event: SIGCONT, listener: Function0[Unit]): REPLServer
@JSName("on")
def on_SIGINT(event: SIGINT, listener: Function0[Unit]): REPLServer
@JSName("on")
def on_SIGTSTP(event: SIGTSTP, listener: Function0[Unit]): REPLServer
@JSName("on")
def on_close(event: close, listener: Function0[Unit]): REPLServer
@JSName("on")
def on_exit(event: exit, listener: Function0[Unit]): REPLServer
@JSName("on")
def on_line(event: line, listener: Function1[String, Unit]): REPLServer
@JSName("on")
def on_pause(event: pause, listener: Function0[Unit]): REPLServer
@JSName("on")
def on_reset(event: reset, listener: Function1[Context, Unit]): REPLServer
@JSName("on")
def on_resume(event: resume, listener: Function0[Unit]): REPLServer
def once(event: String, listener: Function1[Any, Unit]): REPLServer
@JSName("once")
def once_SIGCONT(event: SIGCONT, listener: Function0[Unit]): REPLServer
@JSName("once")
def once_SIGINT(event: SIGINT, listener: Function0[Unit]): REPLServer
@JSName("once")
def once_SIGTSTP(event: SIGTSTP, listener: Function0[Unit]): REPLServer
@JSName("once")
def once_close(event: close, listener: Function0[Unit]): REPLServer
@JSName("once")
def once_exit(event: exit, listener: Function0[Unit]): REPLServer
@JSName("once")
def once_line(event: line, listener: Function1[String, Unit]): REPLServer
@JSName("once")
def once_pause(event: pause, listener: Function0[Unit]): REPLServer
@JSName("once")
def once_reset(event: reset, listener: Function1[Context, Unit]): REPLServer
@JSName("once")
def once_resume(event: resume, listener: Function0[Unit]): REPLServer
def prependListener(event: String, listener: Function1[Any, Unit]): REPLServer
@JSName("prependListener")
def prependListener_SIGCONT(event: SIGCONT, listener: Function0[Unit]): REPLServer
@JSName("prependListener")
def prependListener_SIGINT(event: SIGINT, listener: Function0[Unit]): REPLServer
@JSName("prependListener")
def prependListener_SIGTSTP(event: SIGTSTP, listener: Function0[Unit]): REPLServer
@JSName("prependListener")
def prependListener_close(event: close, listener: Function0[Unit]): REPLServer
@JSName("prependListener")
def prependListener_exit(event: exit, listener: Function0[Unit]): REPLServer
@JSName("prependListener")
def prependListener_line(event: line, listener: Function1[String, Unit]): REPLServer
@JSName("prependListener")
def prependListener_pause(event: pause, listener: Function0[Unit]): REPLServer
@JSName("prependListener")
def prependListener_reset(event: reset, listener: Function1[Context, Unit]): REPLServer
@JSName("prependListener")
def prependListener_resume(event: resume, listener: Function0[Unit]): REPLServer
def prependOnceListener(event: String, listener: Function1[Any, Unit]): REPLServer
@JSName("prependOnceListener")
def prependOnceListener_SIGCONT(event: SIGCONT, listener: Function0[Unit]): REPLServer
@JSName("prependOnceListener")
def prependOnceListener_SIGINT(event: SIGINT, listener: Function0[Unit]): REPLServer
@JSName("prependOnceListener")
def prependOnceListener_SIGTSTP(event: SIGTSTP, listener: Function0[Unit]): REPLServer
@JSName("prependOnceListener")
def prependOnceListener_close(event: close, listener: Function0[Unit]): REPLServer
@JSName("prependOnceListener")
def prependOnceListener_exit(event: exit, listener: Function0[Unit]): REPLServer
@JSName("prependOnceListener")
def prependOnceListener_line(event: line, listener: Function1[String, Unit]): REPLServer
@JSName("prependOnceListener")
def prependOnceListener_pause(event: pause, listener: Function0[Unit]): REPLServer
@JSName("prependOnceListener")
def prependOnceListener_reset(event: reset, listener: Function1[Context, Unit]): REPLServer
@JSName("prependOnceListener")
def prependOnceListener_resume(event: resume, listener: Function0[Unit]): REPLServer
def setupHistory(path: String, cb: Function2[Error | Null, REPLServer, Unit]): Unit

Initializes a history log file for the REPL instance. When executing the Node.js binary and using the command line REPL, a history file is initialized by default. However, this is not the case when creating a REPL programmatically. Use this method to initialize a history log file when working with REPL instances programmatically.

Initializes a history log file for the REPL instance. When executing the Node.js binary and using the command line REPL, a history file is initialized by default. However, this is not the case when creating a REPL programmatically. Use this method to initialize a history log file when working with REPL instances programmatically.

Value Params
path

The path to the history file

def writer(obj: Any): String

Specified in the REPL options, this is the function to invoke to format the output of each command before writing to outputStream. If not specified in the REPL options, this will be a wrapper for util.inspect.

Specified in the REPL options, this is the function to invoke to format the output of each command before writing to outputStream. If not specified in the REPL options, this will be a wrapper for util.inspect.

Inherited methods

def hasOwnProperty(v: String): Boolean
Inherited from
Object
def isPrototypeOf(v: Object): Boolean
Inherited from
Object
def propertyIsEnumerable(v: String): Boolean
Inherited from
Object
def toLocaleString(): String
Inherited from
Object
def valueOf(): Any
Inherited from
Object

Concrete fields

The commands registered via replServer.defineCommand().

The commands registered via replServer.defineCommand().

Specified in the REPL options, this is the function to use for custom Tab auto-completion.

Specified in the REPL options, this is the function to use for custom Tab auto-completion.

The vm.Context provided to the eval function to be used for JavaScript evaluation.

The vm.Context provided to the eval function to be used for JavaScript evaluation.

val editorMode: Boolean

A value indicating whether the REPL is currently in "editor mode".

A value indicating whether the REPL is currently in "editor mode".

See also
val ignoreUndefined: Boolean

Specified in the REPL options, this is a value indicating whether the default writer function should output the result of a command if it evaluates to undefined.

Specified in the REPL options, this is a value indicating whether the default writer function should output the result of a command if it evaluates to undefined.

The Readable stream from which REPL input will be read.

The Readable stream from which REPL input will be read.

val last: Any

The last evaluation result from the REPL (assigned to the _ variable inside of the REPL).

The last evaluation result from the REPL (assigned to the _ variable inside of the REPL).

See also
val lastError: Any

The last error raised inside the REPL (assigned to the _error variable inside of the REPL).

The last error raised inside the REPL (assigned to the _error variable inside of the REPL).

See also
Since

v9.8.0

The Writable stream to which REPL output will be written.

The Writable stream to which REPL output will be written.

val replMode: Symbol

Specified in the REPL options, this is a flag that specifies whether the default eval function should execute all JavaScript commands in strict mode or default (sloppy) mode. Possible values are:

Specified in the REPL options, this is a flag that specifies whether the default eval function should execute all JavaScript commands in strict mode or default (sloppy) mode. Possible values are:

  • repl.REPL_MODE_SLOPPY - evaluates expressions in sloppy mode.
  • repl.REPL_MODE_STRICT - evaluates expressions in strict mode. This is equivalent to prefacing every repl statement with 'use strict'.
val underscoreAssigned: Boolean

A value indicating whether the _ variable has been assigned.

A value indicating whether the _ variable has been assigned.

See also
val underscoreErrAssigned: Boolean

A value indicating whether the _error variable has been assigned.

A value indicating whether the _error variable has been assigned.

See also
Since

v9.8.0

val useColors: Boolean

Specified in the REPL options, this is a value indicating whether the default writer function should include ANSI color styling to REPL output.

Specified in the REPL options, this is a value indicating whether the default writer function should include ANSI color styling to REPL output.

val useGlobal: Boolean

Specified in the REPL options, this is a value indicating whether the default eval function will use the JavaScript global as the context as opposed to creating a new separate context for the REPL instance.

Specified in the REPL options, this is a value indicating whether the default eval function will use the JavaScript global as the context as opposed to creating a new separate context for the REPL instance.