Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

prompt: add HideEntered flag #151

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 11 additions & 3 deletions prompt.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()

Expand Down