From 5f4f780519ce4b31adaacd6df3c53b4469453c32 Mon Sep 17 00:00:00 2001 From: Jeremy Albright Date: Wed, 27 Nov 2019 11:02:02 -0900 Subject: [PATCH 1/5] readline: promote _getCursorPos to public api Aliases Interface._getCursorPos to Interface.getCursorPos, for consumption as a public API. refs: https://github.com/nodejs/node/issues/30347 --- lib/readline.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/readline.js b/lib/readline.js index ea53cd1bbf80c8..07b3a0635960ca 100644 --- a/lib/readline.js +++ b/lib/readline.js @@ -777,6 +777,7 @@ Interface.prototype._getCursorPos = function() { } return { cols: cols, rows: rows }; }; +Interface.prototype.getCursorPos = Interface.prototype._getCursorPos; // This function moves cursor dx places to the right From 417dac1891026fc09fbef2c76808116c28042a2c Mon Sep 17 00:00:00 2001 From: Jeremy Albright Date: Tue, 3 Dec 2019 08:17:57 -0900 Subject: [PATCH 2/5] doc: readline.getCursorPos() documentation --- doc/api/readline.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/doc/api/readline.md b/doc/api/readline.md index ce63dbaa3905f6..18d8ca8c8af5e0 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\]) * Returns: {Object}