spectre.console
spectre.console copied to clipboard
Customise text prompt for secrets
Is your feature request related to a problem? Please describe. The text prompt for secrets echoes asterisks (***) to the console.
This is acceptable. But it feels weird on unixy systems, where the traditional secret prompt (sudo) echoes nothing.
Describe the solution you'd like
It would be nice to be able to customise the masking character. I would set it to null, so nothing is echoed to the console.
Describe alternatives you've considered /
Additional context /
I would like to take a stab at this one if possible.
I am thinking....
I would add a char to TextPrompt that defaults to an asterisk. Maybe named MaskingCharacter. And then whenever we are checking if secret is set instead of using the hardcoded asterisk currently in place, we use the masking character.
Looks like I would need to touch these locations in code.

Consider whether it's char or char?. It should be nullable so one can type "sudo-style" - i.e. without showing feedback.
The alternative is to allow the NUL char - (char)0 - but that is a non-printing char and could cause unintended issues.
I would say public char? Mask { get; set; } = '*'
Began working on this.
Question.
The following occurs on line 129 and 210 of TextPrompt.cs
IsSecret ? "******" : converter(DefaultValue.Value)
~~I was considering creating a private string with just a get that will create a six character string of whatever the Mask char is, and call that in these two spots instead of the hard coded six asterisk.~~
Actually, why not just make a private method that will "Mask" any string passed to it with the Mask character defined...
Not sure if that's the proper way to resolve?
Then I came to wonder if the string should actually be as long as the default value. So if default value is 5 characters, then the mask of the default value should be 5 characters.
Let me know your thoughts!
You can start reviewing what I put together if you like.
https://github.com/spectreconsole/spectre.console/pull/970
This has been merged in :) @patriksvensson do we close this?
Yes, we should 😁
Closed via #970
Thanks guys :+1: