Merge pull request #7225 from chrootsu/node-readline

node: signatures of module "readline" have been changed
This commit is contained in:
Masahiro Wakame
2015-12-23 15:29:12 +09:00
2 changed files with 124 additions and 17 deletions

View File

@@ -438,21 +438,101 @@ module path_tests {
}
////////////////////////////////////////////////////
///ReadLine tests : https://nodejs.org/api/readline.html
/// readline tests : https://nodejs.org/api/readline.html
////////////////////////////////////////////////////
var rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
});
module readline_tests {
let rl: readline.ReadLine;
rl.setPrompt("$>");
rl.prompt();
rl.prompt(true);
{
let options: readline.ReadLineOptions;
let input: NodeJS.ReadableStream;
let output: NodeJS.WritableStream;
let completer: readline.Completer;
let terminal: boolean;
rl.question("do you like typescript?", function(answer: string) {
rl.close();
});
let result: readline.ReadLine;
result = readline.createInterface(options);
result = readline.createInterface(input);
result = readline.createInterface(input, output);
result = readline.createInterface(input, output, completer);
result = readline.createInterface(input, output, completer, terminal);
}
{
let prompt: string;
rl.setPrompt(prompt);
}
{
let preserveCursor: boolean;
rl.prompt();
rl.prompt(preserveCursor);
}
{
let query: string;
let callback: (answer: string) => void;
rl.question(query, callback);
}
{
let result: readline.ReadLine;
result = rl.pause();
}
{
let result: readline.ReadLine;
result = rl.resume();
}
{
rl.close();
}
{
let data: string|Buffer;
let key: readline.Key;
rl.write(data);
rl.write(null, key);
}
{
let stream: NodeJS.WritableStream;
let x: number;
let y: number;
readline.cursorTo(stream, x, y);
}
{
let stream: NodeJS.WritableStream;
let dx: number|string;
let dy: number|string;
readline.moveCursor(stream, dx, dy);
}
{
let stream: NodeJS.WritableStream;
let dir: number;
readline.clearLine(stream, dir);
}
{
let stream: NodeJS.WritableStream;
readline.clearScreenDown(stream);
}
}
//////////////////////////////////////////////////////////////////////
/// Child Process tests: https://nodejs.org/api/child_process.html ///

39
node/node.d.ts vendored
View File

@@ -826,22 +826,49 @@ declare module "readline" {
import * as events from "events";
import * as stream from "stream";
export interface Key {
sequence?: string;
name?: string;
ctrl?: boolean;
meta?: boolean;
shift?: boolean;
}
export interface ReadLine extends events.EventEmitter {
setPrompt(prompt: string): void;
prompt(preserveCursor?: boolean): void;
question(query: string, callback: Function): void;
pause(): void;
resume(): void;
question(query: string, callback: (answer: string) => void): void;
pause(): ReadLine;
resume(): ReadLine;
close(): void;
write(data: any, key?: any): void;
write(data: string|Buffer, key?: Key): void;
}
export interface Completer {
(line: string): CompleterResult;
(line: string, callback: (err: any, result: CompleterResult) => void): any;
}
export interface CompleterResult {
completions: string[];
line: string;
}
export interface ReadLineOptions {
input: NodeJS.ReadableStream;
output: NodeJS.WritableStream;
completer?: Function;
output?: NodeJS.WritableStream;
completer?: Completer;
terminal?: boolean;
historySize?: number;
}
export function createInterface(input: NodeJS.ReadableStream, output?: NodeJS.WritableStream, completer?: Completer, terminal?: boolean): ReadLine;
export function createInterface(options: ReadLineOptions): ReadLine;
export function cursorTo(stream: NodeJS.WritableStream, x: number, y: number): void;
export function moveCursor(stream: NodeJS.WritableStream, dx: number|string, dy: number|string): void;
export function clearLine(stream: NodeJS.WritableStream, dir: number): void;
export function clearScreenDown(stream: NodeJS.WritableStream): void;
}
declare module "vm" {