diff --git a/src/NClap/PublicAPI.Unshipped.txt b/src/NClap/PublicAPI.Unshipped.txt index 7b4d1d0..763cb1c 100644 --- a/src/NClap/PublicAPI.Unshipped.txt +++ b/src/NClap/PublicAPI.Unshipped.txt @@ -3,6 +3,8 @@ NClap.Help.ArgumentHelpOptions.IncludeNamedArgumentValueSyntax.set -> void NClap.Metadata.ArgumentSetAttribute.ExpandLogo.get -> bool NClap.Metadata.ArgumentSetAttribute.ExpandLogo.set -> void NClap.Parser.AttributeBasedArgumentDefinitionFactory +NClap.Repl.ILoopClient.PromptWithColor.get -> NClap.Utilities.ColoredString? +NClap.Repl.ILoopClient.PromptWithColor.set -> void NClap.Types.IArgumentValue.GetAttributes() -> System.Collections.Generic.IEnumerable static NClap.Help.ArgumentSetHelpOptionsExtensions.NoDescription(this NClap.Utilities.FluentBuilder builder) -> NClap.Utilities.FluentBuilder static NClap.Help.ArgumentSetHelpOptionsExtensions.NoEnumValues(this NClap.Utilities.FluentBuilder builder) -> NClap.Utilities.FluentBuilder diff --git a/src/NClap/Repl/ConsoleLoopClient.cs b/src/NClap/Repl/ConsoleLoopClient.cs index 6dd7029..51665f6 100644 --- a/src/NClap/Repl/ConsoleLoopClient.cs +++ b/src/NClap/Repl/ConsoleLoopClient.cs @@ -31,6 +31,15 @@ public string Prompt set => Reader.LineInput.Prompt = value; } + /// + /// The loop prompt (with color). + /// + public ColoredString? PromptWithColor + { + get => Reader.LineInput.Prompt; + set => Reader.LineInput.Prompt = value.GetValueOrDefault(ColoredString.Empty); + } + /// /// The character that starts a comment. /// diff --git a/src/NClap/Repl/ILoopClient.cs b/src/NClap/Repl/ILoopClient.cs index 98021a9..58b6c15 100644 --- a/src/NClap/Repl/ILoopClient.cs +++ b/src/NClap/Repl/ILoopClient.cs @@ -1,4 +1,5 @@ using NClap.ConsoleInput; +using NClap.Utilities; namespace NClap.Repl { @@ -8,10 +9,16 @@ namespace NClap.Repl public interface ILoopClient { /// - /// The loop prompt. + /// The loop prompt. If you wish to use a as your + /// prompt, you should use the property instead. /// string Prompt { get; set; } + /// + /// The loop prompt (with color). + /// + ColoredString? PromptWithColor { get; set; } + /// /// The character that starts a comment. /// diff --git a/src/Tests/UnitTests/Repl/ConsoleLoopClientTests.cs b/src/Tests/UnitTests/Repl/ConsoleLoopClientTests.cs index 20ac2ff..7ad9a7b 100644 --- a/src/Tests/UnitTests/Repl/ConsoleLoopClientTests.cs +++ b/src/Tests/UnitTests/Repl/ConsoleLoopClientTests.cs @@ -91,6 +91,30 @@ public void TestThatPromptsAreObserved() lineInput.Received(1).DisplayPrompt(); } + [TestMethod] + public void TestThatColoredPromptsAreObserved() + { + var prompt = new ColoredString("[Prompt!] ", ConsoleColor.Cyan); + + var reader = Substitute.For(); + var lineInput = Substitute.For(); + + lineInput.Prompt = prompt; + reader.LineInput.Returns(lineInput); + + var client = new ConsoleLoopClient(reader); + client.Prompt.Should().Be(prompt); + + var newPrompt = new ColoredString("NewPrompt", ConsoleColor.Green); + client.PromptWithColor = newPrompt; + client.PromptWithColor.Should().Be(newPrompt); + client.Prompt.Should().Be(newPrompt.ToString()); + lineInput.Prompt.Should().Be(newPrompt); + + client.DisplayPrompt(); + lineInput.Received(1).DisplayPrompt(); + } + [TestMethod] public void TestThatReadLineWorksAsExpected() {