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 | * 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 | }
|
115 |
|
116 | type ReadLine = Interface; // type forwarded for backwards compatiblity
|
117 |
|
118 | type Completer = (line: string) => CompleterResult;
|
119 | type AsyncCompleter = (line: string, callback: (err: any, result: CompleterResult) => void) => any;
|
120 |
|
121 | type CompleterResult = [string[], string];
|
122 |
|
123 | interface ReadLineOptions {
|
124 | input: NodeJS.ReadableStream;
|
125 | output?: NodeJS.WritableStream;
|
126 | completer?: Completer | AsyncCompleter;
|
127 | terminal?: boolean;
|
128 | historySize?: number;
|
129 | prompt?: string;
|
130 | crlfDelay?: number;
|
131 | removeHistoryDuplicates?: boolean;
|
132 | escapeCodeTimeout?: number;
|
133 | }
|
134 |
|
135 | function createInterface(input: NodeJS.ReadableStream, output?: NodeJS.WritableStream, completer?: Completer | AsyncCompleter, terminal?: boolean): Interface;
|
136 | function createInterface(options: ReadLineOptions): Interface;
|
137 |
|
138 | function cursorTo(stream: NodeJS.WritableStream, x: number, y?: number): void;
|
139 | function emitKeypressEvents(stream: NodeJS.ReadableStream, interface?: Interface): void;
|
140 | function moveCursor(stream: NodeJS.WritableStream, dx: number | string, dy: number | string): void;
|
141 | function clearLine(stream: NodeJS.WritableStream, dir: number): void;
|
142 | function clearScreenDown(stream: NodeJS.WritableStream): void;
|
143 | }
|