Skip to content

Commit

Permalink
Support prompt color in loop clients (#68)
Browse files Browse the repository at this point in the history
  • Loading branch information
reubeno authored Jul 28, 2018
1 parent 7f768cb commit d2c2f42
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/NClap/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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<T>() -> System.Collections.Generic.IEnumerable<T>
static NClap.Help.ArgumentSetHelpOptionsExtensions.NoDescription(this NClap.Utilities.FluentBuilder<NClap.Help.ArgumentSetHelpOptions> builder) -> NClap.Utilities.FluentBuilder<NClap.Help.ArgumentSetHelpOptions>
static NClap.Help.ArgumentSetHelpOptionsExtensions.NoEnumValues(this NClap.Utilities.FluentBuilder<NClap.Help.ArgumentSetHelpOptions> builder) -> NClap.Utilities.FluentBuilder<NClap.Help.ArgumentSetHelpOptions>
Expand Down
9 changes: 9 additions & 0 deletions src/NClap/Repl/ConsoleLoopClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,15 @@ public string Prompt
set => Reader.LineInput.Prompt = value;
}

/// <summary>
/// The loop prompt (with color).
/// </summary>
public ColoredString? PromptWithColor
{
get => Reader.LineInput.Prompt;
set => Reader.LineInput.Prompt = value.GetValueOrDefault(ColoredString.Empty);
}

/// <summary>
/// The character that starts a comment.
/// </summary>
Expand Down
9 changes: 8 additions & 1 deletion src/NClap/Repl/ILoopClient.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using NClap.ConsoleInput;
using NClap.Utilities;

namespace NClap.Repl
{
Expand All @@ -8,10 +9,16 @@ namespace NClap.Repl
public interface ILoopClient
{
/// <summary>
/// The loop prompt.
/// The loop prompt. If you wish to use a <see cref="ColoredString"/> as your
/// prompt, you should use the <see cref="PromptWithColor"/> property instead.
/// </summary>
string Prompt { get; set; }

/// <summary>
/// The loop prompt (with color).
/// </summary>
ColoredString? PromptWithColor { get; set; }

/// <summary>
/// The character that starts a comment.
/// </summary>
Expand Down
24 changes: 24 additions & 0 deletions src/Tests/UnitTests/Repl/ConsoleLoopClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<IConsoleReader>();
var lineInput = Substitute.For<IConsoleLineInput>();

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()
{
Expand Down

0 comments on commit d2c2f42

Please sign in to comment.