From 5b49ded22a1c48d279a326fb3d147a284a1a26ab Mon Sep 17 00:00:00 2001 From: Jeremy Albright Date: Wed, 27 Nov 2019 11:02:02 -0900 Subject: [PATCH] readline: promote _getCursorPos to public api Alias _getCursorPos() = getCursorPos() for backwards compatibility. Refs: https://github.com/nodejs/node/issues/30347 PR-URL: https://github.com/nodejs/node/pull/30687 Reviewed-By: James M Snell Reviewed-By: Luigi Pinca Reviewed-By: Anna Henningsen Reviewed-By: Ben Noordhuis Reviewed-By: Ruben Bridgewater --- doc/api/readline.md | 13 +++++ lib/readline.js | 11 ++-- test/parallel/test-readline-interface.js | 68 ++++++++++++------------ test/parallel/test-readline-position.js | 2 +- 4 files changed, 54 insertions(+), 40 deletions(-) diff --git a/doc/api/readline.md b/doc/api/readline.md index ce63dbaa3905f6..bae063f0b2193c 100644 --- a/doc/api/readline.md +++ b/doc/api/readline.md @@ -398,6 +398,19 @@ reading input from a TTY stream. The position of cursor determines the portion of the input string that will be modified as input is processed, as well as the column where the terminal caret will be rendered. +### rl.getCursorPos() + + +* Returns: {Object} + * `rows` {number} the row of the prompt the cursor currently lands on + * `cols` {number} the screen column the cursor currently lands on + +Returns the real position of the cursor in relation to the input +prompt + string. Long input (wrapping) strings, as well as multiple +line prompts are included in the calculations. + ## readline.clearLine(stream, dir\[, callback\])