Skip to content
This repository has been archived by the owner on Apr 19, 2024. It is now read-only.

Allow hiding password length #482

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion survey.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,8 @@ func WithShowCursor(ShowCursor bool) AskOpt {
}
}

// WithHideCharacter sets the default character shown instead of the password for password inputs
// WithHideCharacter sets the default character shown instead of the password for password inputs.
// A space can be used to hide the password length by not printing anything.
func WithHideCharacter(char rune) AskOpt {
return func(options *AskOptions) error {
// set the hide character
Expand Down
4 changes: 4 additions & 0 deletions terminal/runereader.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ func (rr *RuneReader) printChar(char rune, mask rune) error {
_, err := fmt.Fprintf(rr.stdio.Out, "%c", char)
return err
}
// if the mask is a space, don't print anything
if mask == ' ' {
return nil
}
// otherwise print the mask we were given
_, err := fmt.Fprintf(rr.stdio.Out, "%c", mask)
return err
Expand Down
Loading