Software zum Installieren eines Smart-Mirror Frameworks , zum Nutzen von hochschulrelevanten Informationen, auf einem Raspberry-Pi.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

repl.d.ts 18KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395
  1. declare module 'repl' {
  2. import { Interface, Completer, AsyncCompleter } from 'readline';
  3. import { Context } from 'vm';
  4. import { InspectOptions } from 'util';
  5. interface ReplOptions {
  6. /**
  7. * The input prompt to display.
  8. * @default "> "
  9. */
  10. prompt?: string;
  11. /**
  12. * The `Readable` stream from which REPL input will be read.
  13. * @default process.stdin
  14. */
  15. input?: NodeJS.ReadableStream;
  16. /**
  17. * The `Writable` stream to which REPL output will be written.
  18. * @default process.stdout
  19. */
  20. output?: NodeJS.WritableStream;
  21. /**
  22. * If `true`, specifies that the output should be treated as a TTY terminal, and have
  23. * ANSI/VT100 escape codes written to it.
  24. * Default: checking the value of the `isTTY` property on the output stream upon
  25. * instantiation.
  26. */
  27. terminal?: boolean;
  28. /**
  29. * The function to be used when evaluating each given line of input.
  30. * Default: an async wrapper for the JavaScript `eval()` function. An `eval` function can
  31. * error with `repl.Recoverable` to indicate the input was incomplete and prompt for
  32. * additional lines.
  33. *
  34. * @see https://nodejs.org/dist/latest-v10.x/docs/api/repl.html#repl_default_evaluation
  35. * @see https://nodejs.org/dist/latest-v10.x/docs/api/repl.html#repl_custom_evaluation_functions
  36. */
  37. eval?: REPLEval;
  38. /**
  39. * Defines if the repl prints output previews or not.
  40. * @default `true` Always `false` in case `terminal` is falsy.
  41. */
  42. preview?: boolean;
  43. /**
  44. * If `true`, specifies that the default `writer` function should include ANSI color
  45. * styling to REPL output. If a custom `writer` function is provided then this has no
  46. * effect.
  47. * Default: the REPL instance's `terminal` value.
  48. */
  49. useColors?: boolean;
  50. /**
  51. * If `true`, specifies that the default evaluation function will use the JavaScript
  52. * `global` as the context as opposed to creating a new separate context for the REPL
  53. * instance. The node CLI REPL sets this value to `true`.
  54. * Default: `false`.
  55. */
  56. useGlobal?: boolean;
  57. /**
  58. * If `true`, specifies that the default writer will not output the return value of a
  59. * command if it evaluates to `undefined`.
  60. * Default: `false`.
  61. */
  62. ignoreUndefined?: boolean;
  63. /**
  64. * The function to invoke to format the output of each command before writing to `output`.
  65. * Default: a wrapper for `util.inspect`.
  66. *
  67. * @see https://nodejs.org/dist/latest-v10.x/docs/api/repl.html#repl_customizing_repl_output
  68. */
  69. writer?: REPLWriter;
  70. /**
  71. * An optional function used for custom Tab auto completion.
  72. *
  73. * @see https://nodejs.org/dist/latest-v11.x/docs/api/readline.html#readline_use_of_the_completer_function
  74. */
  75. completer?: Completer | AsyncCompleter;
  76. /**
  77. * A flag that specifies whether the default evaluator executes all JavaScript commands in
  78. * strict mode or default (sloppy) mode.
  79. * Accepted values are:
  80. * - `repl.REPL_MODE_SLOPPY` - evaluates expressions in sloppy mode.
  81. * - `repl.REPL_MODE_STRICT` - evaluates expressions in strict mode. This is equivalent to
  82. * prefacing every repl statement with `'use strict'`.
  83. */
  84. replMode?: typeof REPL_MODE_SLOPPY | typeof REPL_MODE_STRICT;
  85. /**
  86. * Stop evaluating the current piece of code when `SIGINT` is received, i.e. `Ctrl+C` is
  87. * pressed. This cannot be used together with a custom `eval` function.
  88. * Default: `false`.
  89. */
  90. breakEvalOnSigint?: boolean;
  91. }
  92. type REPLEval = (this: REPLServer, evalCmd: string, context: Context, file: string, cb: (err: Error | null, result: any) => void) => void;
  93. type REPLWriter = (this: REPLServer, obj: any) => string;
  94. /**
  95. * This is the default "writer" value, if none is passed in the REPL options,
  96. * and it can be overridden by custom print functions.
  97. */
  98. const writer: REPLWriter & { options: InspectOptions };
  99. type REPLCommandAction = (this: REPLServer, text: string) => void;
  100. interface REPLCommand {
  101. /**
  102. * Help text to be displayed when `.help` is entered.
  103. */
  104. help?: string;
  105. /**
  106. * The function to execute, optionally accepting a single string argument.
  107. */
  108. action: REPLCommandAction;
  109. }
  110. /**
  111. * Provides a customizable Read-Eval-Print-Loop (REPL).
  112. *
  113. * Instances of `repl.REPLServer` will accept individual lines of user input, evaluate those
  114. * according to a user-defined evaluation function, then output the result. Input and output
  115. * may be from `stdin` and `stdout`, respectively, or may be connected to any Node.js `stream`.
  116. *
  117. * Instances of `repl.REPLServer` support automatic completion of inputs, simplistic Emacs-style
  118. * line editing, multi-line inputs, ANSI-styled output, saving and restoring current REPL session
  119. * state, error recovery, and customizable evaluation functions.
  120. *
  121. * Instances of `repl.REPLServer` are created using the `repl.start()` method and _should not_
  122. * be created directly using the JavaScript `new` keyword.
  123. *
  124. * @see https://nodejs.org/dist/latest-v10.x/docs/api/repl.html#repl_repl
  125. */
  126. class REPLServer extends Interface {
  127. /**
  128. * The `vm.Context` provided to the `eval` function to be used for JavaScript
  129. * evaluation.
  130. */
  131. readonly context: Context;
  132. /**
  133. * @deprecated since v14.3.0 - Use `input` instead.
  134. */
  135. readonly inputStream: NodeJS.ReadableStream;
  136. /**
  137. * @deprecated since v14.3.0 - Use `output` instead.
  138. */
  139. readonly outputStream: NodeJS.WritableStream;
  140. /**
  141. * The `Readable` stream from which REPL input will be read.
  142. */
  143. readonly input: NodeJS.ReadableStream;
  144. /**
  145. * The `Writable` stream to which REPL output will be written.
  146. */
  147. readonly output: NodeJS.WritableStream;
  148. /**
  149. * The commands registered via `replServer.defineCommand()`.
  150. */
  151. readonly commands: NodeJS.ReadOnlyDict<REPLCommand>;
  152. /**
  153. * A value indicating whether the REPL is currently in "editor mode".
  154. *
  155. * @see https://nodejs.org/dist/latest-v10.x/docs/api/repl.html#repl_commands_and_special_keys
  156. */
  157. readonly editorMode: boolean;
  158. /**
  159. * A value indicating whether the `_` variable has been assigned.
  160. *
  161. * @see https://nodejs.org/dist/latest-v10.x/docs/api/repl.html#repl_assignment_of_the_underscore_variable
  162. */
  163. readonly underscoreAssigned: boolean;
  164. /**
  165. * The last evaluation result from the REPL (assigned to the `_` variable inside of the REPL).
  166. *
  167. * @see https://nodejs.org/dist/latest-v10.x/docs/api/repl.html#repl_assignment_of_the_underscore_variable
  168. */
  169. readonly last: any;
  170. /**
  171. * A value indicating whether the `_error` variable has been assigned.
  172. *
  173. * @since v9.8.0
  174. * @see https://nodejs.org/dist/latest-v10.x/docs/api/repl.html#repl_assignment_of_the_underscore_variable
  175. */
  176. readonly underscoreErrAssigned: boolean;
  177. /**
  178. * The last error raised inside the REPL (assigned to the `_error` variable inside of the REPL).
  179. *
  180. * @since v9.8.0
  181. * @see https://nodejs.org/dist/latest-v10.x/docs/api/repl.html#repl_assignment_of_the_underscore_variable
  182. */
  183. readonly lastError: any;
  184. /**
  185. * Specified in the REPL options, this is the function to be used when evaluating each
  186. * given line of input. If not specified in the REPL options, this is an async wrapper
  187. * for the JavaScript `eval()` function.
  188. */
  189. readonly eval: REPLEval;
  190. /**
  191. * Specified in the REPL options, this is a value indicating whether the default
  192. * `writer` function should include ANSI color styling to REPL output.
  193. */
  194. readonly useColors: boolean;
  195. /**
  196. * Specified in the REPL options, this is a value indicating whether the default `eval`
  197. * function will use the JavaScript `global` as the context as opposed to creating a new
  198. * separate context for the REPL instance.
  199. */
  200. readonly useGlobal: boolean;
  201. /**
  202. * Specified in the REPL options, this is a value indicating whether the default `writer`
  203. * function should output the result of a command if it evaluates to `undefined`.
  204. */
  205. readonly ignoreUndefined: boolean;
  206. /**
  207. * Specified in the REPL options, this is the function to invoke to format the output of
  208. * each command before writing to `outputStream`. If not specified in the REPL options,
  209. * this will be a wrapper for `util.inspect`.
  210. */
  211. readonly writer: REPLWriter;
  212. /**
  213. * Specified in the REPL options, this is the function to use for custom Tab auto-completion.
  214. */
  215. readonly completer: Completer | AsyncCompleter;
  216. /**
  217. * Specified in the REPL options, this is a flag that specifies whether the default `eval`
  218. * function should execute all JavaScript commands in strict mode or default (sloppy) mode.
  219. * Possible values are:
  220. * - `repl.REPL_MODE_SLOPPY` - evaluates expressions in sloppy mode.
  221. * - `repl.REPL_MODE_STRICT` - evaluates expressions in strict mode. This is equivalent to
  222. * prefacing every repl statement with `'use strict'`.
  223. */
  224. readonly replMode: typeof REPL_MODE_SLOPPY | typeof REPL_MODE_STRICT;
  225. /**
  226. * NOTE: According to the documentation:
  227. *
  228. * > Instances of `repl.REPLServer` are created using the `repl.start()` method and
  229. * > _should not_ be created directly using the JavaScript `new` keyword.
  230. *
  231. * `REPLServer` cannot be subclassed due to implementation specifics in NodeJS.
  232. *
  233. * @see https://nodejs.org/dist/latest-v10.x/docs/api/repl.html#repl_class_replserver
  234. */
  235. private constructor();
  236. /**
  237. * Used to add new `.`-prefixed commands to the REPL instance. Such commands are invoked
  238. * by typing a `.` followed by the `keyword`.
  239. *
  240. * @param keyword The command keyword (_without_ a leading `.` character).
  241. * @param cmd The function to invoke when the command is processed.
  242. *
  243. * @see https://nodejs.org/dist/latest-v10.x/docs/api/repl.html#repl_replserver_definecommand_keyword_cmd
  244. */
  245. defineCommand(keyword: string, cmd: REPLCommandAction | REPLCommand): void;
  246. /**
  247. * Readies the REPL instance for input from the user, printing the configured `prompt` to a
  248. * new line in the `output` and resuming the `input` to accept new input.
  249. *
  250. * When multi-line input is being entered, an ellipsis is printed rather than the 'prompt'.
  251. *
  252. * This method is primarily intended to be called from within the action function for
  253. * commands registered using the `replServer.defineCommand()` method.
  254. *
  255. * @param preserveCursor When `true`, the cursor placement will not be reset to `0`.
  256. */
  257. displayPrompt(preserveCursor?: boolean): void;
  258. /**
  259. * Clears any command that has been buffered but not yet executed.
  260. *
  261. * This method is primarily intended to be called from within the action function for
  262. * commands registered using the `replServer.defineCommand()` method.
  263. *
  264. * @since v9.0.0
  265. */
  266. clearBufferedCommand(): void;
  267. /**
  268. * Initializes a history log file for the REPL instance. When executing the
  269. * Node.js binary and using the command line REPL, a history file is initialized
  270. * by default. However, this is not the case when creating a REPL
  271. * programmatically. Use this method to initialize a history log file when working
  272. * with REPL instances programmatically.
  273. * @param path The path to the history file
  274. */
  275. setupHistory(path: string, cb: (err: Error | null, repl: this) => void): void;
  276. /**
  277. * events.EventEmitter
  278. * 1. close - inherited from `readline.Interface`
  279. * 2. line - inherited from `readline.Interface`
  280. * 3. pause - inherited from `readline.Interface`
  281. * 4. resume - inherited from `readline.Interface`
  282. * 5. SIGCONT - inherited from `readline.Interface`
  283. * 6. SIGINT - inherited from `readline.Interface`
  284. * 7. SIGTSTP - inherited from `readline.Interface`
  285. * 8. exit
  286. * 9. reset
  287. */
  288. addListener(event: string, listener: (...args: any[]) => void): this;
  289. addListener(event: "close", listener: () => void): this;
  290. addListener(event: "line", listener: (input: string) => void): this;
  291. addListener(event: "pause", listener: () => void): this;
  292. addListener(event: "resume", listener: () => void): this;
  293. addListener(event: "SIGCONT", listener: () => void): this;
  294. addListener(event: "SIGINT", listener: () => void): this;
  295. addListener(event: "SIGTSTP", listener: () => void): this;
  296. addListener(event: "exit", listener: () => void): this;
  297. addListener(event: "reset", listener: (context: Context) => void): this;
  298. emit(event: string | symbol, ...args: any[]): boolean;
  299. emit(event: "close"): boolean;
  300. emit(event: "line", input: string): boolean;
  301. emit(event: "pause"): boolean;
  302. emit(event: "resume"): boolean;
  303. emit(event: "SIGCONT"): boolean;
  304. emit(event: "SIGINT"): boolean;
  305. emit(event: "SIGTSTP"): boolean;
  306. emit(event: "exit"): boolean;
  307. emit(event: "reset", context: Context): boolean;
  308. on(event: string, listener: (...args: any[]) => void): this;
  309. on(event: "close", listener: () => void): this;
  310. on(event: "line", listener: (input: string) => void): this;
  311. on(event: "pause", listener: () => void): this;
  312. on(event: "resume", listener: () => void): this;
  313. on(event: "SIGCONT", listener: () => void): this;
  314. on(event: "SIGINT", listener: () => void): this;
  315. on(event: "SIGTSTP", listener: () => void): this;
  316. on(event: "exit", listener: () => void): this;
  317. on(event: "reset", listener: (context: Context) => void): this;
  318. once(event: string, listener: (...args: any[]) => void): this;
  319. once(event: "close", listener: () => void): this;
  320. once(event: "line", listener: (input: string) => void): this;
  321. once(event: "pause", listener: () => void): this;
  322. once(event: "resume", listener: () => void): this;
  323. once(event: "SIGCONT", listener: () => void): this;
  324. once(event: "SIGINT", listener: () => void): this;
  325. once(event: "SIGTSTP", listener: () => void): this;
  326. once(event: "exit", listener: () => void): this;
  327. once(event: "reset", listener: (context: Context) => void): this;
  328. prependListener(event: string, listener: (...args: any[]) => void): this;
  329. prependListener(event: "close", listener: () => void): this;
  330. prependListener(event: "line", listener: (input: string) => void): this;
  331. prependListener(event: "pause", listener: () => void): this;
  332. prependListener(event: "resume", listener: () => void): this;
  333. prependListener(event: "SIGCONT", listener: () => void): this;
  334. prependListener(event: "SIGINT", listener: () => void): this;
  335. prependListener(event: "SIGTSTP", listener: () => void): this;
  336. prependListener(event: "exit", listener: () => void): this;
  337. prependListener(event: "reset", listener: (context: Context) => void): this;
  338. prependOnceListener(event: string, listener: (...args: any[]) => void): this;
  339. prependOnceListener(event: "close", listener: () => void): this;
  340. prependOnceListener(event: "line", listener: (input: string) => void): this;
  341. prependOnceListener(event: "pause", listener: () => void): this;
  342. prependOnceListener(event: "resume", listener: () => void): this;
  343. prependOnceListener(event: "SIGCONT", listener: () => void): this;
  344. prependOnceListener(event: "SIGINT", listener: () => void): this;
  345. prependOnceListener(event: "SIGTSTP", listener: () => void): this;
  346. prependOnceListener(event: "exit", listener: () => void): this;
  347. prependOnceListener(event: "reset", listener: (context: Context) => void): this;
  348. }
  349. /**
  350. * A flag passed in the REPL options. Evaluates expressions in sloppy mode.
  351. */
  352. const REPL_MODE_SLOPPY: unique symbol;
  353. /**
  354. * A flag passed in the REPL options. Evaluates expressions in strict mode.
  355. * This is equivalent to prefacing every repl statement with `'use strict'`.
  356. */
  357. const REPL_MODE_STRICT: unique symbol;
  358. /**
  359. * Creates and starts a `repl.REPLServer` instance.
  360. *
  361. * @param options The options for the `REPLServer`. If `options` is a string, then it specifies
  362. * the input prompt.
  363. */
  364. function start(options?: string | ReplOptions): REPLServer;
  365. /**
  366. * Indicates a recoverable error that a `REPLServer` can use to support multi-line input.
  367. *
  368. * @see https://nodejs.org/dist/latest-v10.x/docs/api/repl.html#repl_recoverable_errors
  369. */
  370. class Recoverable extends SyntaxError {
  371. err: Error;
  372. constructor(err: Error);
  373. }
  374. }