From ab9a46a5b82cb0aa3d42980d202352850578e9c1 Mon Sep 17 00:00:00 2001 From: Jeremy Albright <1935258+Js-Brecht@users.noreply.github.com> Date: Tue, 19 Nov 2019 13:11:58 -1000 Subject: [PATCH] [node/readline] expose line/cursor properties + tests 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 6cb572e3136dd8..861606986f38de 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 36884df6f3981a..664b6b7de21489 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 9c25da49827f76..102532830e8e23 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: *