Skip to content

Commit

Permalink
[node/readline] expose line/cursor properties + tests
Browse files Browse the repository at this point in the history
The current "line" and "cursor" states are often necessary when developing applications that use readline for prompts.

See nodejs/node#30347
  • Loading branch information
Js-Brecht committed Nov 26, 2019
1 parent 0c600dc commit ab9a46a
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
7 changes: 7 additions & 0 deletions types/node/readline.d.ts
Expand Up @@ -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:
*
Expand Down
11 changes: 11 additions & 0 deletions types/node/test/readline.ts
Expand Up @@ -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;
Expand Down
7 changes: 7 additions & 0 deletions types/node/v10/readline.d.ts
Expand Up @@ -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:
*
Expand Down

0 comments on commit ab9a46a

Please sign in to comment.