From d1baae364033e3c1c8e87b8e834248dce2bcd8fc Mon Sep 17 00:00:00 2001 From: Mattias Runge-Broberg Date: Sun, 31 May 2020 19:34:17 +0200 Subject: [PATCH] readline: add getPrompt to get the current prompt MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Since there is a setPrompt() there should be a getPrompt(). There are use-cases where it is needed to know what the current prompt is. Adding a getPrompt() negates the need to store the set prompt externally or read the internal _prompt which would be bad practice. Co-authored-by: Colin Ihrig PR-URL: https://github.com/nodejs/node/pull/33675 Reviewed-By: Colin Ihrig Reviewed-By: Anto Aravinth Reviewed-By: Benjamin Gruenbaum Reviewed-By: Ruben Bridgewater Reviewed-By: Michaël Zasso Reviewed-By: James M Snell Reviewed-By: Juan José Arboleda --- doc/api/readline.md | 9 +++++++++ lib/internal/repl/utils.js | 12 ++++++------ lib/readline.js | 5 +++++ test/parallel/test-readline-interface.js | 12 +++++++++++- test/parallel/test-repl-options.js | 2 +- 5 files changed, 32 insertions(+), 8 deletions(-) diff --git a/doc/api/readline.md b/doc/api/readline.md index 14b416b1e8045b..8f96616fd235c6 100644 --- a/doc/api/readline.md +++ b/doc/api/readline.md @@ -283,6 +283,15 @@ added: v0.1.98 The `rl.setPrompt()` method sets the prompt that will be written to `output` whenever `rl.prompt()` is called. +### `rl.getPrompt()` + + +* Returns: {string} the current prompt string + +The `rl.getPrompt()` method returns the current prompt used by `rl.prompt()`. + ### `rl.write(data[, key])`