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 | readonly line: string;
|
20 |
|
21 | readonly cursor: number;
|
22 |
|
23 | |
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 | protected constructor(input: NodeJS.ReadableStream, output?: NodeJS.WritableStream, completer?: Completer | AsyncCompleter, terminal?: boolean);
|
32 | /**
|
33 | * NOTE: According to the documentation:
|
34 | *
|
35 | * > Instances of the `readline.Interface` class are constructed using the
|
36 | * > `readline.createInterface()` method.
|
37 | *
|
38 | * @see https://nodejs.org/dist/latest-v10.x/docs/api/readline.html#readline_class_interface
|
39 | */
|
40 | protected constructor(options: ReadLineOptions);
|
41 |
|
42 | setPrompt(prompt: string): void;
|
43 | prompt(preserveCursor?: boolean): void;
|
44 | question(query: string, callback: (answer: string) => void): void;
|
45 | pause(): this;
|
46 | resume(): this;
|
47 | close(): void;
|
48 | write(data: string | Buffer, key?: Key): void;
|
49 |
|
50 | /**
|
51 | * Returns the real position of the cursor in relation to the input
|
52 | * prompt + string. Long input (wrapping) strings, as well as multiple
|
53 | * line prompts are included in the calculations.
|
54 | */
|
55 | getCursorPos(): CursorPos;
|
56 |
|
57 | /**
|
58 | * events.EventEmitter
|
59 | * 1. close
|
60 | * 2. line
|
61 | * 3. pause
|
62 | * 4. resume
|
63 | * 5. SIGCONT
|
64 | * 6. SIGINT
|
65 | * 7. SIGTSTP
|
66 | */
|
67 |
|
68 | addListener(event: string, listener: (...args: any[]) => void): this;
|
69 | addListener(event: "close", listener: () => void): this;
|
70 | addListener(event: "line", listener: (input: string) => void): this;
|
71 | addListener(event: "pause", listener: () => void): this;
|
72 | addListener(event: "resume", listener: () => void): this;
|
73 | addListener(event: "SIGCONT", listener: () => void): this;
|
74 | addListener(event: "SIGINT", listener: () => void): this;
|
75 | addListener(event: "SIGTSTP", listener: () => void): this;
|
76 |
|
77 | emit(event: string | symbol, ...args: any[]): boolean;
|
78 | emit(event: "close"): boolean;
|
79 | emit(event: "line", input: string): boolean;
|
80 | emit(event: "pause"): boolean;
|
81 | emit(event: "resume"): boolean;
|
82 | emit(event: "SIGCONT"): boolean;
|
83 | emit(event: "SIGINT"): boolean;
|
84 | emit(event: "SIGTSTP"): boolean;
|
85 |
|
86 | on(event: string, listener: (...args: any[]) => void): this;
|
87 | on(event: "close", listener: () => void): this;
|
88 | on(event: "line", listener: (input: string) => void): this;
|
89 | on(event: "pause", listener: () => void): this;
|
90 | on(event: "resume", listener: () => void): this;
|
91 | on(event: "SIGCONT", listener: () => void): this;
|
92 | on(event: "SIGINT", listener: () => void): this;
|
93 | on(event: "SIGTSTP", listener: () => void): this;
|
94 |
|
95 | once(event: string, listener: (...args: any[]) => void): this;
|
96 | once(event: "close", listener: () => void): this;
|
97 | once(event: "line", listener: (input: string) => void): this;
|
98 | once(event: "pause", listener: () => void): this;
|
99 | once(event: "resume", listener: () => void): this;
|
100 | once(event: "SIGCONT", listener: () => void): this;
|
101 | once(event: "SIGINT", listener: () => void): this;
|
102 | once(event: "SIGTSTP", listener: () => void): this;
|
103 |
|
104 | prependListener(event: string, listener: (...args: any[]) => void): this;
|
105 | prependListener(event: "close", listener: () => void): this;
|
106 | prependListener(event: "line", listener: (input: string) => void): this;
|
107 | prependListener(event: "pause", listener: () => void): this;
|
108 | prependListener(event: "resume", listener: () => void): this;
|
109 | prependListener(event: "SIGCONT", listener: () => void): this;
|
110 | prependListener(event: "SIGINT", listener: () => void): this;
|
111 | prependListener(event: "SIGTSTP", listener: () => void): this;
|
112 |
|
113 | prependOnceListener(event: string, listener: (...args: any[]) => void): this;
|
114 | prependOnceListener(event: "close", listener: () => void): this;
|
115 | prependOnceListener(event: "line", listener: (input: string) => void): this;
|
116 | prependOnceListener(event: "pause", listener: () => void): this;
|
117 | prependOnceListener(event: "resume", listener: () => void): this;
|
118 | prependOnceListener(event: "SIGCONT", listener: () => void): this;
|
119 | prependOnceListener(event: "SIGINT", listener: () => void): this;
|
120 | prependOnceListener(event: "SIGTSTP", listener: () => void): this;
|
121 | [Symbol.asyncIterator](): AsyncIterableIterator<string>;
|
122 | }
|
123 |
|
124 | type ReadLine = Interface; // type forwarded for backwards compatiblity
|
125 |
|
126 | type Completer = (line: string) => CompleterResult;
|
127 | type AsyncCompleter = (line: string, callback: (err?: null | Error, result?: CompleterResult) => void) => any;
|
128 |
|
129 | type CompleterResult = [string[], string];
|
130 |
|
131 | interface ReadLineOptions {
|
132 | input: NodeJS.ReadableStream;
|
133 | output?: NodeJS.WritableStream;
|
134 | completer?: Completer | AsyncCompleter;
|
135 | terminal?: boolean;
|
136 | historySize?: number;
|
137 | prompt?: string;
|
138 | crlfDelay?: number;
|
139 | removeHistoryDuplicates?: boolean;
|
140 | escapeCodeTimeout?: number;
|
141 | }
|
142 |
|
143 | function createInterface(input: NodeJS.ReadableStream, output?: NodeJS.WritableStream, completer?: Completer | AsyncCompleter, terminal?: boolean): Interface;
|
144 | function createInterface(options: ReadLineOptions): Interface;
|
145 | function emitKeypressEvents(stream: NodeJS.ReadableStream, readlineInterface?: Interface): void;
|
146 |
|
147 | type Direction = -1 | 0 | 1;
|
148 |
|
149 | interface CursorPos {
|
150 | rows: number;
|
151 | cols: number;
|
152 | }
|
153 |
|
154 | |
155 |
|
156 |
|
157 | function clearLine(stream: NodeJS.WritableStream, dir: Direction, callback?: () => void): boolean;
|
158 | |
159 |
|
160 |
|
161 | function clearScreenDown(stream: NodeJS.WritableStream, callback?: () => void): boolean;
|
162 | |
163 |
|
164 |
|
165 | function cursorTo(stream: NodeJS.WritableStream, x: number, y?: number, callback?: () => void): boolean;
|
166 | |
167 |
|
168 |
|
169 | function moveCursor(stream: NodeJS.WritableStream, dx: number, dy: number, callback?: () => void): boolean;
|
170 | }
|