diff options
author | cjihrig <cjihrig@gmail.com> | 2019-07-13 20:10:17 -0400 |
---|---|---|
committer | Michaƫl Zasso <targos@protonmail.com> | 2019-07-20 11:13:06 +0200 |
commit | caee9106acd54832b529ac7f8ce7d9a8da170a4e (patch) | |
tree | e2eba29f3f0bb20091065b02aaa75917bdf77ffc /lib | |
parent | 4a7e20ff81770916c38def86106f469d444a65d7 (diff) | |
download | android-node-v8-caee9106acd54832b529ac7f8ce7d9a8da170a4e.tar.gz android-node-v8-caee9106acd54832b529ac7f8ce7d9a8da170a4e.tar.bz2 android-node-v8-caee9106acd54832b529ac7f8ce7d9a8da170a4e.zip |
readline: expose stream API in cursorTo()
This commit adds an optional callback to cursorTo(), which is
passed to the stream's write() method. It also exposes the
return value of write().
PR-URL: https://github.com/nodejs/node/pull/28674
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/readline.js | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/lib/readline.js b/lib/readline.js index 2190c620bd..77b9dbc6c8 100644 --- a/lib/readline.js +++ b/lib/readline.js @@ -1189,21 +1189,21 @@ function emitKeypressEvents(stream, iface) { * moves the cursor to the x and y coordinate on the given stream */ -function cursorTo(stream, x, y) { - if (stream === null || stream === undefined) - return; +function cursorTo(stream, x, y, callback) { + if (callback !== undefined && typeof callback !== 'function') + throw new ERR_INVALID_CALLBACK(callback); - if (typeof x !== 'number' && typeof y !== 'number') - return; + if (stream == null || (typeof x !== 'number' && typeof y !== 'number')) { + if (typeof callback === 'function') + process.nextTick(callback); + return true; + } if (typeof x !== 'number') throw new ERR_INVALID_CURSOR_POS(); - if (typeof y !== 'number') { - stream.write(CSI`${x + 1}G`); - } else { - stream.write(CSI`${y + 1};${x + 1}H`); - } + const data = typeof y !== 'number' ? CSI`${x + 1}G` : CSI`${y + 1};${x + 1}H`; + return stream.write(data, callback); } /** |