mirror of
https://github.com/nsnail/spectre.console.git
synced 2025-06-19 05:18:16 +08:00
Custom mask for secret (#970)
* Masking Character added, not yet used. * Setting the masking character can be chained with other extensions. * Added string extension for masking, and replaced hardcoded asterisks. * Check if mask is null first. * Fixed Typo in previous test and added new test for custom masks. * Added tests for masking with null character * Added docs and example. * Adjusted extensions so that Mask is integrated into Secret extension. Updated Exampls and Tests accordingly
This commit is contained in:
@ -33,7 +33,13 @@ namespace Prompt
|
||||
var age = AskAge();
|
||||
|
||||
WriteDivider("Secrets");
|
||||
var password = AskPassword();
|
||||
var password = AskPassword();
|
||||
|
||||
WriteDivider("Mask");
|
||||
var mask = AskPasswordWithCustomMask();
|
||||
|
||||
WriteDivider("Null Mask");
|
||||
var nullMask = AskPasswordWithNullMask();
|
||||
|
||||
WriteDivider("Optional");
|
||||
var color = AskColor();
|
||||
@ -48,7 +54,9 @@ namespace Prompt
|
||||
.AddRow("[grey]Favorite fruit[/]", fruit)
|
||||
.AddRow("[grey]Favorite sport[/]", sport)
|
||||
.AddRow("[grey]Age[/]", age.ToString())
|
||||
.AddRow("[grey]Password[/]", password)
|
||||
.AddRow("[grey]Password[/]", password)
|
||||
.AddRow("[grey]Mask[/]", mask)
|
||||
.AddRow("[grey]Null Mask[/]", nullMask)
|
||||
.AddRow("[grey]Favorite color[/]", string.IsNullOrEmpty(color) ? "Unknown" : color));
|
||||
}
|
||||
|
||||
@ -145,6 +153,22 @@ namespace Prompt
|
||||
new TextPrompt<string>("Enter [green]password[/]?")
|
||||
.PromptStyle("red")
|
||||
.Secret());
|
||||
}
|
||||
|
||||
public static string AskPasswordWithCustomMask()
|
||||
{
|
||||
return AnsiConsole.Prompt(
|
||||
new TextPrompt<string>("Enter [green]password[/]?")
|
||||
.PromptStyle("red")
|
||||
.Secret('-'));
|
||||
}
|
||||
|
||||
public static string AskPasswordWithNullMask()
|
||||
{
|
||||
return AnsiConsole.Prompt(
|
||||
new TextPrompt<string>("Enter [green]password[/]?")
|
||||
.PromptStyle("red")
|
||||
.Secret(null));
|
||||
}
|
||||
|
||||
public static string AskColor()
|
||||
|
Reference in New Issue
Block a user