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 | // Need direct access to line/cursor data, for use in external processes
|
---|
16 | // see: https://github.com/nodejs/node/issues/30347
|
---|
17 | /** The current input data */
|
---|
18 | readonly line: string;
|
---|
19 | /** The current cursor position in the input line */
|
---|
20 | readonly cursor: number;
|
---|
21 |
|
---|
22 | /**
|
---|
23 | * NOTE: According to the documentation:
|
---|
24 | *
|
---|
25 | * > Instances of the `readline.Interface` class are constructed using the
|
---|
26 | * > `readline.createInterface()` method.
|
---|
27 | *
|
---|
28 | * @see https://nodejs.org/dist/latest-v10.x/docs/api/readline.html#readline_class_interface
|
---|
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 | write(data: undefined | null | string | Buffer, key: Key): void;
|
---|
49 |
|
---|
50 | /**
|
---|
51 | * events.EventEmitter
|
---|
52 | * 1. close
|
---|
53 | * 2. line
|
---|
54 | * 3. pause
|
---|
55 | * 4. resume
|
---|
56 | * 5. SIGCONT
|
---|
57 | * 6. SIGINT
|
---|
58 | * 7. SIGTSTP
|
---|
59 | */
|
---|
60 |
|
---|
61 | addListener(event: string, listener: (...args: any[]) => void): this;
|
---|
62 | addListener(event: "close", listener: () => void): this;
|
---|
63 | addListener(event: "line", listener: (input: string) => void): this;
|
---|
64 | addListener(event: "pause", listener: () => void): this;
|
---|
65 | addListener(event: "resume", listener: () => void): this;
|
---|
66 | addListener(event: "SIGCONT", listener: () => void): this;
|
---|
67 | addListener(event: "SIGINT", listener: () => void): this;
|
---|
68 | addListener(event: "SIGTSTP", listener: () => void): this;
|
---|
69 |
|
---|
70 | emit(event: string | symbol, ...args: any[]): boolean;
|
---|
71 | emit(event: "close"): boolean;
|
---|
72 | emit(event: "line", input: string): boolean;
|
---|
73 | emit(event: "pause"): boolean;
|
---|
74 | emit(event: "resume"): boolean;
|
---|
75 | emit(event: "SIGCONT"): boolean;
|
---|
76 | emit(event: "SIGINT"): boolean;
|
---|
77 | emit(event: "SIGTSTP"): boolean;
|
---|
78 |
|
---|
79 | on(event: string, listener: (...args: any[]) => void): this;
|
---|
80 | on(event: "close", listener: () => void): this;
|
---|
81 | on(event: "line", listener: (input: string) => void): this;
|
---|
82 | on(event: "pause", listener: () => void): this;
|
---|
83 | on(event: "resume", listener: () => void): this;
|
---|
84 | on(event: "SIGCONT", listener: () => void): this;
|
---|
85 | on(event: "SIGINT", listener: () => void): this;
|
---|
86 | on(event: "SIGTSTP", listener: () => void): this;
|
---|
87 |
|
---|
88 | once(event: string, listener: (...args: any[]) => void): this;
|
---|
89 | once(event: "close", listener: () => void): this;
|
---|
90 | once(event: "line", listener: (input: string) => void): this;
|
---|
91 | once(event: "pause", listener: () => void): this;
|
---|
92 | once(event: "resume", listener: () => void): this;
|
---|
93 | once(event: "SIGCONT", listener: () => void): this;
|
---|
94 | once(event: "SIGINT", listener: () => void): this;
|
---|
95 | once(event: "SIGTSTP", listener: () => void): this;
|
---|
96 |
|
---|
97 | prependListener(event: string, listener: (...args: any[]) => void): this;
|
---|
98 | prependListener(event: "close", listener: () => void): this;
|
---|
99 | prependListener(event: "line", listener: (input: string) => void): this;
|
---|
100 | prependListener(event: "pause", listener: () => void): this;
|
---|
101 | prependListener(event: "resume", listener: () => void): this;
|
---|
102 | prependListener(event: "SIGCONT", listener: () => void): this;
|
---|
103 | prependListener(event: "SIGINT", listener: () => void): this;
|
---|
104 | prependListener(event: "SIGTSTP", listener: () => void): this;
|
---|
105 |
|
---|
106 | prependOnceListener(event: string, listener: (...args: any[]) => void): this;
|
---|
107 | prependOnceListener(event: "close", listener: () => void): this;
|
---|
108 | prependOnceListener(event: "line", listener: (input: string) => void): this;
|
---|
109 | prependOnceListener(event: "pause", listener: () => void): this;
|
---|
110 | prependOnceListener(event: "resume", listener: () => void): this;
|
---|
111 | prependOnceListener(event: "SIGCONT", listener: () => void): this;
|
---|
112 | prependOnceListener(event: "SIGINT", listener: () => void): this;
|
---|
113 | prependOnceListener(event: "SIGTSTP", listener: () => void): this;
|
---|
114 | [Symbol.asyncIterator](): AsyncIterableIterator<string>;
|
---|
115 | }
|
---|
116 |
|
---|
117 | type ReadLine = Interface; // type forwarded for backwards compatiblity
|
---|
118 |
|
---|
119 | type Completer = (line: string) => CompleterResult;
|
---|
120 | type AsyncCompleter = (line: string, callback: (err?: null | Error, result?: CompleterResult) => void) => any;
|
---|
121 |
|
---|
122 | type CompleterResult = [string[], string];
|
---|
123 |
|
---|
124 | interface ReadLineOptions {
|
---|
125 | input: NodeJS.ReadableStream;
|
---|
126 | output?: NodeJS.WritableStream | undefined;
|
---|
127 | completer?: Completer | AsyncCompleter | undefined;
|
---|
128 | terminal?: boolean | undefined;
|
---|
129 | historySize?: number | undefined;
|
---|
130 | prompt?: string | undefined;
|
---|
131 | crlfDelay?: number | undefined;
|
---|
132 | removeHistoryDuplicates?: boolean | undefined;
|
---|
133 | escapeCodeTimeout?: number | undefined;
|
---|
134 | }
|
---|
135 |
|
---|
136 | function createInterface(input: NodeJS.ReadableStream, output?: NodeJS.WritableStream, completer?: Completer | AsyncCompleter, terminal?: boolean): Interface;
|
---|
137 | function createInterface(options: ReadLineOptions): Interface;
|
---|
138 | function emitKeypressEvents(stream: NodeJS.ReadableStream, readlineInterface?: Interface): void;
|
---|
139 |
|
---|
140 | type Direction = -1 | 0 | 1;
|
---|
141 |
|
---|
142 | /**
|
---|
143 | * Clears the current line of this WriteStream in a direction identified by `dir`.
|
---|
144 | */
|
---|
145 | function clearLine(stream: NodeJS.WritableStream, dir: Direction, callback?: () => void): boolean;
|
---|
146 | /**
|
---|
147 | * Clears this `WriteStream` from the current cursor down.
|
---|
148 | */
|
---|
149 | function clearScreenDown(stream: NodeJS.WritableStream, callback?: () => void): boolean;
|
---|
150 | /**
|
---|
151 | * Moves this WriteStream's cursor to the specified position.
|
---|
152 | */
|
---|
153 | function cursorTo(stream: NodeJS.WritableStream, x: number, y?: number, callback?: () => void): boolean;
|
---|
154 | /**
|
---|
155 | * Moves this WriteStream's cursor relative to its current position.
|
---|
156 | */
|
---|
157 | function moveCursor(stream: NodeJS.WritableStream, dx: number, dy: number, callback?: () => void): boolean;
|
---|
158 | }
|
---|