From 361491009c119a9063b88de9581d5ebc5cb440c4 Mon Sep 17 00:00:00 2001 From: Yaroslav Skopets Date: Thu, 30 Apr 2020 01:09:02 +0200 Subject: [PATCH] prompt: add `HideEntered` flag --- prompt.go | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/prompt.go b/prompt.go index 97ff373..85fe4ed 100644 --- a/prompt.go +++ b/prompt.go @@ -33,6 +33,9 @@ type Prompt struct { // allows hiding private information like passwords. Mask rune + // HideEntered sets whether to hide the text after the user has pressed enter. + HideEntered bool + // Templates can be used to customize the prompt output. If nil is passed, the // default templates are used. See the PromptTemplates docs for more info. Templates *PromptTemplates @@ -234,9 +237,14 @@ func (p *Prompt) Run() (string, error) { } } - sb.Reset() - sb.Write(prompt) - sb.Flush() + if p.HideEntered { + clearScreen(sb) + } else { + sb.Reset() + sb.Write(prompt) + sb.Flush() + } + rl.Write([]byte(showCursor)) rl.Close()