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

Commit

Permalink
Allow hiding password length
Browse files Browse the repository at this point in the history
  • Loading branch information
szh committed Apr 3, 2023
1 parent fa37277 commit 24dfd56
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
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

0 comments on commit 24dfd56

Please sign in to comment.