[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
This commit is contained in:
Jeremy Albright 2019-12-09 11:42:48 -09:00 committed by Andrew Casey
parent 3eea7ab402
commit 141ff986a4
3 changed files with 25 additions and 0 deletions

View File

@ -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:
*

View File

@ -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;

View File

@ -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:
*