diff options
author | cjihrig <cjihrig@gmail.com> | 2019-07-13 18:08:19 -0400 |
---|---|---|
committer | cjihrig <cjihrig@gmail.com> | 2019-07-16 10:03:01 -0400 |
commit | 79cc8bb24117aa40e101971610d5813d927f9fbe (patch) | |
tree | 343fd848f4da40b42f7f76cf36d9bb36bffd3a08 /lib/readline.js | |
parent | d5737a8537544e4c763249db4ce4fbd7dacfa9fe (diff) | |
download | android-node-v8-79cc8bb24117aa40e101971610d5813d927f9fbe.tar.gz android-node-v8-79cc8bb24117aa40e101971610d5813d927f9fbe.tar.bz2 android-node-v8-79cc8bb24117aa40e101971610d5813d927f9fbe.zip |
readline: expose stream API in clearLine()
This commit adds an optional callback to clearLine(), 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/readline.js')
-rw-r--r-- | lib/readline.js | 22 |
1 files changed, 10 insertions, 12 deletions
diff --git a/lib/readline.js b/lib/readline.js index d50b1d5a44..6a60df82c7 100644 --- a/lib/readline.js +++ b/lib/readline.js @@ -1234,20 +1234,18 @@ function moveCursor(stream, dx, dy) { * 0 for the entire line */ -function clearLine(stream, dir) { - if (stream === null || stream === undefined) - return; +function clearLine(stream, dir, callback) { + if (callback !== undefined && typeof callback !== 'function') + throw new ERR_INVALID_CALLBACK(callback); - if (dir < 0) { - // to the beginning - stream.write(kClearToBeginning); - } else if (dir > 0) { - // to the end - stream.write(kClearToEnd); - } else { - // entire line - stream.write(kClearLine); + if (stream === null || stream === undefined) { + if (typeof callback === 'function') + process.nextTick(callback); + return true; } + + const type = dir < 0 ? kClearToBeginning : dir > 0 ? kClearToEnd : kClearLine; + return stream.write(type, callback); } /** |