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