Skip to content

Commit 65bc794

Browse files
committed
Update REPL interfaces
1 parent ab74519 commit 65bc794

File tree

4 files changed

+144
-46
lines changed

4 files changed

+144
-46
lines changed

0.10/node.d.ts

Lines changed: 47 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -677,8 +677,8 @@ declare module "punycode" {
677677
}
678678

679679
declare module "repl" {
680-
import stream = require("stream");
681-
import events = require("events");
680+
import { EventEmitter } from "events";
681+
import { Interface } from "readline";
682682

683683
export interface ReplOptions {
684684
prompt?: string;
@@ -691,29 +691,63 @@ declare module "repl" {
691691
ignoreUndefined?: boolean;
692692
writer?: Function;
693693
}
694-
export function start(options: ReplOptions): events.EventEmitter;
694+
695+
export function start(options: ReplOptions): REPLServer;
696+
697+
export type REPLCommand = (this: REPLServer, rest: string) => void;
698+
699+
export class REPLServer extends Interface {
700+
inputStream: NodeJS.ReadableStream;
701+
outputStream: NodeJS.WritableStream;
702+
useColors: boolean;
703+
commands: {
704+
[command: string]: REPLCommand;
705+
};
706+
defineCommand (keyword: string, cmd: REPLCommand | { help: string, action: REPLCommand }): void;
707+
displayPrompt (preserveCursor?: boolean): void;
708+
setPrompt (prompt: string): void;
709+
}
695710
}
696711

697712
declare module "readline" {
698713
import events = require("events");
699-
import stream = require("stream");
700714

701-
export interface ReadLine extends events.EventEmitter {
702-
setPrompt(prompt: string, length: number): void;
715+
export interface Key {
716+
sequence?: string;
717+
name?: string;
718+
ctrl?: boolean;
719+
meta?: boolean;
720+
shift?: boolean;
721+
}
722+
723+
export class Interface extends events.EventEmitter {
724+
setPrompt(prompt: string): void;
703725
prompt(preserveCursor?: boolean): void;
704-
question(query: string, callback: Function): void;
705-
pause(): void;
706-
resume(): void;
726+
question(query: string, callback: (answer: string) => void): void;
727+
pause(): this;
728+
resume(): this;
707729
close(): void;
708-
write(data: any, key?: any): void;
730+
write(data: string | Buffer, key?: Key): void;
731+
}
732+
733+
export interface Completer {
734+
(line: string): CompleterResult;
735+
(line: string, callback: (err: any, result: CompleterResult) => void): any;
709736
}
710-
export interface ReadLineOptions {
737+
738+
export interface CompleterResult {
739+
completions: string[];
740+
line: string;
741+
}
742+
743+
export interface InterfaceOptions {
711744
input: NodeJS.ReadableStream;
712745
output: NodeJS.WritableStream;
713-
completer?: Function;
746+
completer?: Completer;
714747
terminal?: boolean;
715748
}
716-
export function createInterface(options: ReadLineOptions): ReadLine;
749+
750+
export function createInterface(options: InterfaceOptions): Interface;
717751
}
718752

719753
declare module "vm" {

0.12/node.d.ts

Lines changed: 47 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -882,8 +882,8 @@ declare module "punycode" {
882882
}
883883

884884
declare module "repl" {
885-
import * as stream from "stream";
886-
import * as events from "events";
885+
import { EventEmitter } from "events";
886+
import { Interface } from "readline";
887887

888888
export interface ReplOptions {
889889
prompt?: string;
@@ -896,29 +896,63 @@ declare module "repl" {
896896
ignoreUndefined?: boolean;
897897
writer?: Function;
898898
}
899-
export function start(options: ReplOptions): events.EventEmitter;
899+
900+
export function start(options: ReplOptions): REPLServer;
901+
902+
export type REPLCommand = (this: REPLServer, rest: string) => void;
903+
904+
export class REPLServer extends Interface {
905+
inputStream: NodeJS.ReadableStream;
906+
outputStream: NodeJS.WritableStream;
907+
useColors: boolean;
908+
commands: {
909+
[command: string]: REPLCommand;
910+
};
911+
defineCommand (keyword: string, cmd: REPLCommand | { help: string, action: REPLCommand }): void;
912+
displayPrompt (preserveCursor?: boolean): void;
913+
setPrompt (prompt: string): void;
914+
}
900915
}
901916

902917
declare module "readline" {
903-
import * as events from "events";
904-
import * as stream from "stream";
918+
import events = require("events");
905919

906-
export interface ReadLine extends events.EventEmitter {
920+
export interface Key {
921+
sequence?: string;
922+
name?: string;
923+
ctrl?: boolean;
924+
meta?: boolean;
925+
shift?: boolean;
926+
}
927+
928+
export class Interface extends events.EventEmitter {
907929
setPrompt(prompt: string): void;
908930
prompt(preserveCursor?: boolean): void;
909-
question(query: string, callback: Function): void;
910-
pause(): void;
911-
resume(): void;
931+
question(query: string, callback: (answer: string) => void): void;
932+
pause(): this;
933+
resume(): this;
912934
close(): void;
913-
write(data: any, key?: any): void;
935+
write(data: string | Buffer, key?: Key): void;
936+
}
937+
938+
export interface Completer {
939+
(line: string): CompleterResult;
940+
(line: string, callback: (err: any, result: CompleterResult) => void): any;
914941
}
915-
export interface ReadLineOptions {
942+
943+
export interface CompleterResult {
944+
completions: string[];
945+
line: string;
946+
}
947+
948+
export interface InterfaceOptions {
916949
input: NodeJS.ReadableStream;
917950
output: NodeJS.WritableStream;
918-
completer?: Function;
951+
completer?: Completer;
919952
terminal?: boolean;
920953
}
921-
export function createInterface(options: ReadLineOptions): ReadLine;
954+
955+
export function createInterface(options: InterfaceOptions): Interface;
922956
}
923957

924958
declare module "vm" {

4.0/node.d.ts

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1100,8 +1100,8 @@ declare module "punycode" {
11001100
}
11011101

11021102
declare module "repl" {
1103-
import * as stream from "stream";
1104-
import * as events from "events";
1103+
import { EventEmitter } from "events";
1104+
import { Interface } from "readline";
11051105

11061106
export interface ReplOptions {
11071107
prompt?: string;
@@ -1114,12 +1114,26 @@ declare module "repl" {
11141114
ignoreUndefined?: boolean;
11151115
writer?: Function;
11161116
}
1117-
export function start(options: ReplOptions): events.EventEmitter;
1117+
1118+
export function start(options: ReplOptions): REPLServer;
1119+
1120+
export type REPLCommand = (this: REPLServer, rest: string) => void;
1121+
1122+
export class REPLServer extends Interface {
1123+
inputStream: NodeJS.ReadableStream;
1124+
outputStream: NodeJS.WritableStream;
1125+
useColors: boolean;
1126+
commands: {
1127+
[command: string]: REPLCommand;
1128+
};
1129+
defineCommand (keyword: string, cmd: REPLCommand | { help: string, action: REPLCommand }): void;
1130+
displayPrompt (preserveCursor?: boolean): void;
1131+
setPrompt (prompt: string): void;
1132+
}
11181133
}
11191134

11201135
declare module "readline" {
11211136
import * as events from "events";
1122-
import * as stream from "stream";
11231137

11241138
export interface Key {
11251139
sequence?: string;
@@ -1129,14 +1143,14 @@ declare module "readline" {
11291143
shift?: boolean;
11301144
}
11311145

1132-
export interface ReadLine extends events.EventEmitter {
1146+
export class Interface extends events.EventEmitter {
11331147
setPrompt(prompt: string): void;
11341148
prompt(preserveCursor?: boolean): void;
11351149
question(query: string, callback: (answer: string) => void): void;
1136-
pause(): ReadLine;
1137-
resume(): ReadLine;
1150+
pause(): this;
1151+
resume(): this;
11381152
close(): void;
1139-
write(data: string|Buffer, key?: Key): void;
1153+
write(data: string | Buffer, key?: Key): void;
11401154
}
11411155

11421156
export interface Completer {
@@ -1149,16 +1163,16 @@ declare module "readline" {
11491163
line: string;
11501164
}
11511165

1152-
export interface ReadLineOptions {
1166+
export interface InterfaceOptions {
11531167
input: NodeJS.ReadableStream;
11541168
output?: NodeJS.WritableStream;
11551169
completer?: Completer;
11561170
terminal?: boolean;
11571171
historySize?: number;
11581172
}
11591173

1160-
export function createInterface(input: NodeJS.ReadableStream, output?: NodeJS.WritableStream, completer?: Completer, terminal?: boolean): ReadLine;
1161-
export function createInterface(options: ReadLineOptions): ReadLine;
1174+
export function createInterface(input: NodeJS.ReadableStream, output?: NodeJS.WritableStream, completer?: Completer, terminal?: boolean): Interface;
1175+
export function createInterface(options: InterfaceOptions): Interface;
11621176

11631177
export function cursorTo(stream: NodeJS.WritableStream, x: number, y: number): void;
11641178
export function moveCursor(stream: NodeJS.WritableStream, dx: number|string, dy: number|string): void;

6.0/node.d.ts

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1116,8 +1116,8 @@ declare module "punycode" {
11161116
}
11171117

11181118
declare module "repl" {
1119-
import * as stream from "stream";
1120-
import * as events from "events";
1119+
import { EventEmitter } from "events";
1120+
import { Interface } from "readline";
11211121

11221122
export interface ReplOptions {
11231123
prompt?: string;
@@ -1130,7 +1130,23 @@ declare module "repl" {
11301130
ignoreUndefined?: boolean;
11311131
writer?: Function;
11321132
}
1133-
export function start(options: ReplOptions): events.EventEmitter;
1133+
1134+
export function start(options: ReplOptions): REPLServer;
1135+
1136+
export type REPLCommand = (this: REPLServer, rest: string) => void;
1137+
1138+
export class REPLServer extends Interface {
1139+
inputStream: NodeJS.ReadableStream;
1140+
outputStream: NodeJS.WritableStream;
1141+
useColors: boolean;
1142+
commands: {
1143+
[command: string]: REPLCommand;
1144+
};
1145+
defineCommand (keyword: string, cmd: REPLCommand | { help: string, action: REPLCommand }): void;
1146+
displayPrompt (preserveCursor?: boolean): void;
1147+
setPrompt (prompt: string): void;
1148+
turnOffEditorMode (): void;
1149+
}
11341150

11351151
export class Recoverable extends SyntaxError {
11361152
err: Error;
@@ -1150,12 +1166,12 @@ declare module "readline" {
11501166
shift?: boolean;
11511167
}
11521168

1153-
export interface ReadLine extends events.EventEmitter {
1169+
export class Interface extends events.EventEmitter {
11541170
setPrompt(prompt: string): void;
11551171
prompt(preserveCursor?: boolean): void;
11561172
question(query: string, callback: (answer: string) => void): void;
1157-
pause(): ReadLine;
1158-
resume(): ReadLine;
1173+
pause(): this;
1174+
resume(): this;
11591175
close(): void;
11601176
write(data: string | Buffer, key?: Key): void;
11611177
}
@@ -1170,16 +1186,16 @@ declare module "readline" {
11701186
line: string;
11711187
}
11721188

1173-
export interface ReadLineOptions {
1189+
export interface InterfaceOptions {
11741190
input: NodeJS.ReadableStream;
11751191
output?: NodeJS.WritableStream;
11761192
completer?: Completer;
11771193
terminal?: boolean;
11781194
historySize?: number;
11791195
}
11801196

1181-
export function createInterface(input: NodeJS.ReadableStream, output?: NodeJS.WritableStream, completer?: Completer, terminal?: boolean): ReadLine;
1182-
export function createInterface(options: ReadLineOptions): ReadLine;
1197+
export function createInterface(input: NodeJS.ReadableStream, output?: NodeJS.WritableStream, completer?: Completer, terminal?: boolean): Interface;
1198+
export function createInterface(options: InterfaceOptions): Interface;
11831199

11841200
export function cursorTo(stream: NodeJS.WritableStream, x: number, y: number): void;
11851201
export function moveCursor(stream: NodeJS.WritableStream, dx: number | string, dy: number | string): void;

0 commit comments

Comments
 (0)