From f315b21523447b1cd2abee50720346f7b11fbaf4 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 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 --- 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 d572eb4bb29f9b..ecf9a777763215 100644 --- a/doc/api/readline.md +++ b/doc/api/readline.md @@ -281,6 +281,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])`