Skip to content

Commit d2c2f42

Browse files
authored
Support prompt color in loop clients (#68)
1 parent 7f768cb commit d2c2f42

File tree

4 files changed

+43
-1
lines changed

4 files changed

+43
-1
lines changed

src/NClap/PublicAPI.Unshipped.txt

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ NClap.Help.ArgumentHelpOptions.IncludeNamedArgumentValueSyntax.set -> void
33
NClap.Metadata.ArgumentSetAttribute.ExpandLogo.get -> bool
44
NClap.Metadata.ArgumentSetAttribute.ExpandLogo.set -> void
55
NClap.Parser.AttributeBasedArgumentDefinitionFactory
6+
NClap.Repl.ILoopClient.PromptWithColor.get -> NClap.Utilities.ColoredString?
7+
NClap.Repl.ILoopClient.PromptWithColor.set -> void
68
NClap.Types.IArgumentValue.GetAttributes<T>() -> System.Collections.Generic.IEnumerable<T>
79
static NClap.Help.ArgumentSetHelpOptionsExtensions.NoDescription(this NClap.Utilities.FluentBuilder<NClap.Help.ArgumentSetHelpOptions> builder) -> NClap.Utilities.FluentBuilder<NClap.Help.ArgumentSetHelpOptions>
810
static NClap.Help.ArgumentSetHelpOptionsExtensions.NoEnumValues(this NClap.Utilities.FluentBuilder<NClap.Help.ArgumentSetHelpOptions> builder) -> NClap.Utilities.FluentBuilder<NClap.Help.ArgumentSetHelpOptions>

src/NClap/Repl/ConsoleLoopClient.cs

+9
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,15 @@ public string Prompt
3131
set => Reader.LineInput.Prompt = value;
3232
}
3333

34+
/// <summary>
35+
/// The loop prompt (with color).
36+
/// </summary>
37+
public ColoredString? PromptWithColor
38+
{
39+
get => Reader.LineInput.Prompt;
40+
set => Reader.LineInput.Prompt = value.GetValueOrDefault(ColoredString.Empty);
41+
}
42+
3443
/// <summary>
3544
/// The character that starts a comment.
3645
/// </summary>

src/NClap/Repl/ILoopClient.cs

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using NClap.ConsoleInput;
2+
using NClap.Utilities;
23

34
namespace NClap.Repl
45
{
@@ -8,10 +9,16 @@ namespace NClap.Repl
89
public interface ILoopClient
910
{
1011
/// <summary>
11-
/// The loop prompt.
12+
/// The loop prompt. If you wish to use a <see cref="ColoredString"/> as your
13+
/// prompt, you should use the <see cref="PromptWithColor"/> property instead.
1214
/// </summary>
1315
string Prompt { get; set; }
1416

17+
/// <summary>
18+
/// The loop prompt (with color).
19+
/// </summary>
20+
ColoredString? PromptWithColor { get; set; }
21+
1522
/// <summary>
1623
/// The character that starts a comment.
1724
/// </summary>

src/Tests/UnitTests/Repl/ConsoleLoopClientTests.cs

+24
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,30 @@ public void TestThatPromptsAreObserved()
9191
lineInput.Received(1).DisplayPrompt();
9292
}
9393

94+
[TestMethod]
95+
public void TestThatColoredPromptsAreObserved()
96+
{
97+
var prompt = new ColoredString("[Prompt!] ", ConsoleColor.Cyan);
98+
99+
var reader = Substitute.For<IConsoleReader>();
100+
var lineInput = Substitute.For<IConsoleLineInput>();
101+
102+
lineInput.Prompt = prompt;
103+
reader.LineInput.Returns(lineInput);
104+
105+
var client = new ConsoleLoopClient(reader);
106+
client.Prompt.Should().Be(prompt);
107+
108+
var newPrompt = new ColoredString("NewPrompt", ConsoleColor.Green);
109+
client.PromptWithColor = newPrompt;
110+
client.PromptWithColor.Should().Be(newPrompt);
111+
client.Prompt.Should().Be(newPrompt.ToString());
112+
lineInput.Prompt.Should().Be(newPrompt);
113+
114+
client.DisplayPrompt();
115+
lineInput.Received(1).DisplayPrompt();
116+
}
117+
94118
[TestMethod]
95119
public void TestThatReadLineWorksAsExpected()
96120
{

0 commit comments

Comments
 (0)