From 141ff986a4fc92efa2ef5ebce179faca6880aeda Mon Sep 17 00:00:00 2001 From: Jeremy Albright <1935258+Js-Brecht@users.noreply.github.com> Date: Mon, 9 Dec 2019 11:42:48 -0900 Subject: [PATCH] [node/readline] expose line/cursor properties + tests (#40513) The current "line" and "cursor" states are often necessary when developing applications that use readline for prompts. See https://github.com/nodejs/node/issues/30347 --- types/node/readline.d.ts | 7 +++++++ types/node/test/readline.ts | 11 +++++++++++ types/node/v10/readline.d.ts | 7 +++++++ 3 files changed, 25 insertions(+) diff --git a/types/node/readline.d.ts b/types/node/readline.d.ts index 6cb572e313..861606986f 100644 --- a/types/node/readline.d.ts +++ b/types/node/readline.d.ts @@ -13,6 +13,13 @@ declare module "readline" { class Interface extends events.EventEmitter { readonly terminal: boolean; + // Need direct access to line/cursor data, for use in external processes + // see: https://github.com/nodejs/node/issues/30347 + /** The current input data */ + readonly line: string; + /** The current cursor position in the input line */ + readonly cursor: number; + /** * NOTE: According to the documentation: * diff --git a/types/node/test/readline.ts b/types/node/test/readline.ts index 36884df6f3..664b6b7de2 100644 --- a/types/node/test/readline.ts +++ b/types/node/test/readline.ts @@ -71,6 +71,17 @@ const rl: readline.ReadLine = readline.createInterface(new stream.Readable()); rl.write('asd', key); } +{ + const data: string | Buffer = "test"; + rl.line; // $ExpectType string + rl.cursor; // $ExpectType number + + rl.write(data); + + rl.line; // $ExpectType string + rl.cursor; // $ExpectType number +} + { const strm: NodeJS.WritableStream = new stream.Writable(); const x = 1; diff --git a/types/node/v10/readline.d.ts b/types/node/v10/readline.d.ts index 9c25da4982..102532830e 100644 --- a/types/node/v10/readline.d.ts +++ b/types/node/v10/readline.d.ts @@ -13,6 +13,13 @@ declare module "readline" { class Interface extends events.EventEmitter { readonly terminal: boolean; + // Need direct access to line/cursor data, for use in external processes + // see: https://github.com/nodejs/node/issues/30347 + /** The current input data */ + readonly line: string; + /** The current cursor position in the input line */ + readonly cursor: number; + /** * NOTE: According to the documentation: *