aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorcjihrig <cjihrig@gmail.com>2019-07-13 20:10:17 -0400
committercjihrig <cjihrig@gmail.com>2019-07-16 10:03:19 -0400
commit462f43824f6af577bde27da76d9f33365eddcfe7 (patch)
tree12c9d41f2b0856a23a265f9227518f03bf3703e5 /lib
parent795c7482f24c0c2f1b2db8d004b03ea373b6381b (diff)
downloadandroid-node-v8-462f43824f6af577bde27da76d9f33365eddcfe7.tar.gz
android-node-v8-462f43824f6af577bde27da76d9f33365eddcfe7.tar.bz2
android-node-v8-462f43824f6af577bde27da76d9f33365eddcfe7.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.js20
1 files changed, 10 insertions, 10 deletions
diff --git a/lib/readline.js b/lib/readline.js
index cccae73eec..f21d5bd77b 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);
}
/**