设计与特性


repl 模块导出 repl.REPLServer 类。 当运行时,repl.REPLServer 的实例将接受用户输入的单行,根据用户定义的评估函数评估它们,然后输出结果。 输入和输出可能分别来自 stdinstdout,也可能连接到任何 Node.js

repl.REPLServer 实例支持自动补全输入、补全预览、简单的 Emacs 风格的行编辑、多行输入、类 ZSH 的反向搜索、类 ZSH 的基于子串的历史搜索、ANSI 风格的输出、保存和恢复当前 REPL 会话状态、错误恢复和可定制的评估函数。 不支持 ANSI 风格和 Emacs 风格的行编辑的终端会自动回退到有限的功能集。

The repl module exports the repl.REPLServer class. While running, 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, completion preview, 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 ANSI styles and Emacs-style line editing automatically fall back to a limited feature set.