mirror of
https://github.com/nodejs/node.git
synced 2026-11-26 21:58:26 -05:00
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>
This commit is contained in:
1 parent
4a7e20ff81
commit
caee9106ac
3 files changed
+36
-17
No files matched your search
+10
-10
@@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in new issue
Block a user