mirror of
https://github.com/nsnail/spectre.console.git
synced 2025-06-19 21:38:16 +08:00
Add option to configure the style of the choices list and the default value in TextPrompt (#681)
* Allow setting the style of the default value in TextPrompt Add property "DefaultValueStyle" to TextPrompt which allows setting the style in which the default value is rendered. When no style is set, the value is displayed as green text, keeping the existing behavior. * Allow setting the style in which a TextPrompt's choices are displayed Add property "ChoicesStyle" to TextPrompt which allows setting the style in the prompt's choices are rendered. When no style is set, choices are displayed as blue text, keeping the existing behavior.
This commit is contained in:
@ -0,0 +1 @@
|
||||
Enter Value: [38;5;12m[Choice 1/Choice 2][0m: Choice 2
|
@ -0,0 +1 @@
|
||||
Enter Value: [38;5;9m[Choice 1/Choice 2][0m: Choice 2
|
@ -0,0 +1 @@
|
||||
Enter Value: [38;5;2m(default)[0m: Input
|
@ -0,0 +1 @@
|
||||
Enter Value: [38;5;9m(default)[0m: Input
|
@ -241,4 +241,96 @@ public sealed class TextPromptTests
|
||||
// Then
|
||||
return Verifier.Verify(console.Output);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Expectation("DefaultValueStyleNotSet")]
|
||||
public Task Uses_default_style_for_default_value_if_no_style_is_set()
|
||||
{
|
||||
// Given
|
||||
var console = new TestConsole
|
||||
{
|
||||
EmitAnsiSequences = true,
|
||||
};
|
||||
console.Input.PushTextWithEnter("Input");
|
||||
|
||||
var prompt = new TextPrompt<string>("Enter Value:")
|
||||
.ShowDefaultValue()
|
||||
.DefaultValue("default");
|
||||
|
||||
// When
|
||||
console.Prompt(prompt);
|
||||
|
||||
// Then
|
||||
return Verifier.Verify(console.Output);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Expectation("DefaultValueStyleSet")]
|
||||
public Task Uses_specified_default_value_style()
|
||||
{
|
||||
// Given
|
||||
var console = new TestConsole
|
||||
{
|
||||
EmitAnsiSequences = true,
|
||||
};
|
||||
console.Input.PushTextWithEnter("Input");
|
||||
|
||||
var prompt = new TextPrompt<string>("Enter Value:")
|
||||
.ShowDefaultValue()
|
||||
.DefaultValue("default")
|
||||
.DefaultValueStyle(new Style(foreground: Color.Red));
|
||||
|
||||
// When
|
||||
console.Prompt(prompt);
|
||||
|
||||
// Then
|
||||
return Verifier.Verify(console.Output);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Expectation("ChoicesStyleNotSet")]
|
||||
public Task Uses_default_style_for_choices_if_no_style_is_set()
|
||||
{
|
||||
// Given
|
||||
var console = new TestConsole
|
||||
{
|
||||
EmitAnsiSequences = true,
|
||||
};
|
||||
console.Input.PushTextWithEnter("Choice 2");
|
||||
|
||||
var prompt = new TextPrompt<string>("Enter Value:")
|
||||
.ShowChoices()
|
||||
.AddChoice("Choice 1")
|
||||
.AddChoice("Choice 2");
|
||||
|
||||
// When
|
||||
console.Prompt(prompt);
|
||||
|
||||
// Then
|
||||
return Verifier.Verify(console.Output);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Expectation("ChoicesStyleSet")]
|
||||
public Task Uses_the_specified_choices_style()
|
||||
{
|
||||
// Given
|
||||
var console = new TestConsole
|
||||
{
|
||||
EmitAnsiSequences = true,
|
||||
};
|
||||
console.Input.PushTextWithEnter("Choice 2");
|
||||
|
||||
var prompt = new TextPrompt<string>("Enter Value:")
|
||||
.ShowChoices()
|
||||
.AddChoice("Choice 1")
|
||||
.AddChoice("Choice 2")
|
||||
.ChoicesStyle(new Style(foreground: Color.Red));
|
||||
|
||||
// When
|
||||
console.Prompt(prompt);
|
||||
|
||||
// Then
|
||||
return Verifier.Verify(console.Output);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user