From 95f332f3d2cc4320c2714e67cb72cc7782868843 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 9fd8f1f1ecacc1..c6d468156af3fb 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])`