1 | declare module "readline" {
|
2 | import * as events from "events";
|
3 | import * as stream from "stream";
|
4 |
|
5 | interface Key {
|
6 | sequence?: string;
|
7 | name?: string;
|
8 | ctrl?: boolean;
|
9 | meta?: boolean;
|
10 | shift?: boolean;
|
11 | }
|
12 |
|
13 | class Interface extends events.EventEmitter {
|
14 | readonly terminal: boolean;
|
15 |
|
16 | |
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 | protected constructor(input: NodeJS.ReadableStream, output?: NodeJS.WritableStream, completer?: Completer | AsyncCompleter, terminal?: boolean);
|
25 | /**
|
26 | * NOTE: According to the documentation:
|
27 | *
|
28 | * > Instances of the `readline.Interface` class are constructed using the
|
29 | * > `readline.createInterface()` method.
|
30 | *
|
31 | * @see https://nodejs.org/dist/latest-v10.x/docs/api/readline.html#readline_class_interface
|
32 | */
|
33 | protected constructor(options: ReadLineOptions);
|
34 |
|
35 | setPrompt(prompt: string): void;
|
36 | prompt(preserveCursor?: boolean): void;
|
37 | question(query: string, callback: (answer: string) => void): void;
|
38 | pause(): this;
|
39 | resume(): this;
|
40 | close(): void;
|
41 | write(data: string | Buffer, key?: Key): void;
|
42 |
|
43 | /**
|
44 | * events.EventEmitter
|
45 | * 1. close
|
46 | * 2. line
|
47 | * 3. pause
|
48 | * 4. resume
|
49 | * 5. SIGCONT
|
50 | * 6. SIGINT
|
51 | * 7. SIGTSTP
|
52 | */
|
53 |
|
54 | addListener(event: string, listener: (...args: any[]) => void): this;
|
55 | addListener(event: "close", listener: () => void): this;
|
56 | addListener(event: "line", listener: (input: string) => void): this;
|
57 | addListener(event: "pause", listener: () => void): this;
|
58 | addListener(event: "resume", listener: () => void): this;
|
59 | addListener(event: "SIGCONT", listener: () => void): this;
|
60 | addListener(event: "SIGINT", listener: () => void): this;
|
61 | addListener(event: "SIGTSTP", listener: () => void): this;
|
62 |
|
63 | emit(event: string | symbol, ...args: any[]): boolean;
|
64 | emit(event: "close"): boolean;
|
65 | emit(event: "line", input: string): boolean;
|
66 | emit(event: "pause"): boolean;
|
67 | emit(event: "resume"): boolean;
|
68 | emit(event: "SIGCONT"): boolean;
|
69 | emit(event: "SIGINT"): boolean;
|
70 | emit(event: "SIGTSTP"): boolean;
|
71 |
|
72 | on(event: string, listener: (...args: any[]) => void): this;
|
73 | on(event: "close", listener: () => void): this;
|
74 | on(event: "line", listener: (input: string) => void): this;
|
75 | on(event: "pause", listener: () => void): this;
|
76 | on(event: "resume", listener: () => void): this;
|
77 | on(event: "SIGCONT", listener: () => void): this;
|
78 | on(event: "SIGINT", listener: () => void): this;
|
79 | on(event: "SIGTSTP", listener: () => void): this;
|
80 |
|
81 | once(event: string, listener: (...args: any[]) => void): this;
|
82 | once(event: "close", listener: () => void): this;
|
83 | once(event: "line", listener: (input: string) => void): this;
|
84 | once(event: "pause", listener: () => void): this;
|
85 | once(event: "resume", listener: () => void): this;
|
86 | once(event: "SIGCONT", listener: () => void): this;
|
87 | once(event: "SIGINT", listener: () => void): this;
|
88 | once(event: "SIGTSTP", listener: () => void): this;
|
89 |
|
90 | prependListener(event: string, listener: (...args: any[]) => void): this;
|
91 | prependListener(event: "close", listener: () => void): this;
|
92 | prependListener(event: "line", listener: (input: string) => void): this;
|
93 | prependListener(event: "pause", listener: () => void): this;
|
94 | prependListener(event: "resume", listener: () => void): this;
|
95 | prependListener(event: "SIGCONT", listener: () => void): this;
|
96 | prependListener(event: "SIGINT", listener: () => void): this;
|
97 | prependListener(event: "SIGTSTP", listener: () => void): this;
|
98 |
|
99 | prependOnceListener(event: string, listener: (...args: any[]) => void): this;
|
100 | prependOnceListener(event: "close", listener: () => void): this;
|
101 | prependOnceListener(event: "line", listener: (input: string) => void): this;
|
102 | prependOnceListener(event: "pause", listener: () => void): this;
|
103 | prependOnceListener(event: "resume", listener: () => void): this;
|
104 | prependOnceListener(event: "SIGCONT", listener: () => void): this;
|
105 | prependOnceListener(event: "SIGINT", listener: () => void): this;
|
106 | prependOnceListener(event: "SIGTSTP", listener: () => void): this;
|
107 | [Symbol.asyncIterator](): AsyncIterableIterator<string>;
|
108 | }
|
109 |
|
110 | type ReadLine = Interface; // type forwarded for backwards compatiblity
|
111 |
|
112 | type Completer = (line: string) => CompleterResult;
|
113 | type AsyncCompleter = (line: string, callback: (err?: null | Error, result?: CompleterResult) => void) => any;
|
114 |
|
115 | type CompleterResult = [string[], string];
|
116 |
|
117 | interface ReadLineOptions {
|
118 | input: NodeJS.ReadableStream;
|
119 | output?: NodeJS.WritableStream;
|
120 | completer?: Completer | AsyncCompleter;
|
121 | terminal?: boolean;
|
122 | historySize?: number;
|
123 | prompt?: string;
|
124 | crlfDelay?: number;
|
125 | removeHistoryDuplicates?: boolean;
|
126 | }
|
127 |
|
128 | function createInterface(input: NodeJS.ReadableStream, output?: NodeJS.WritableStream, completer?: Completer | AsyncCompleter, terminal?: boolean): Interface;
|
129 | function createInterface(options: ReadLineOptions): Interface;
|
130 |
|
131 | function cursorTo(stream: NodeJS.WritableStream, x: number, y?: number): void;
|
132 | function emitKeypressEvents(stream: NodeJS.ReadableStream, interface?: Interface): void;
|
133 | function moveCursor(stream: NodeJS.WritableStream, dx: number | string, dy: number | string): void;
|
134 | function clearLine(stream: NodeJS.WritableStream, dir: number): void;
|
135 | function clearScreenDown(stream: NodeJS.WritableStream): void;
|
136 | }
|