-
Notifications
You must be signed in to change notification settings - Fork 365
Added :scriptpacks REPL command #1005
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
5e1113e
ef895af
158b781
b76b85a
fbb6923
efb76d5
2d0a88b
507169b
01b8536
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,20 +30,22 @@ public string CommandName | |
| public object Execute(IRepl repl, object[] args) | ||
| { | ||
| var packContexts = repl.ScriptPackSession.Contexts; | ||
| var originalColor = _console.ForegroundColor; | ||
| _console.ForegroundColor = ConsoleColor.Yellow; | ||
|
|
||
| if (packContexts.IsNullOrEmpty()) | ||
| { | ||
| _console.WriteLine("There are no script packs available in this REPL session"); | ||
| _console.ForegroundColor = originalColor; | ||
| return null; | ||
| } | ||
|
|
||
| var importedNamespaces = repl.Namespaces.Union(repl.ScriptPackSession.Namespaces).ToArray(); | ||
| var originalColor = _console.ForegroundColor; | ||
|
|
||
| foreach (var packContext in packContexts) | ||
| { | ||
| var contextType = packContext.GetType(); | ||
|
|
||
| _console.ForegroundColor = ConsoleColor.Yellow; | ||
|
|
||
| _console.WriteLine(contextType.ToString()); | ||
| _console.ForegroundColor = originalColor; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because the yellow colour is set outside this loop, the first script pack name will be printed in yellow, but every subsequent one will be printed in green. The yellow should be set just before writing out the name of the script pack. Also, since this a static state mutation, after setting the yellow, the (Once I pull my finger out and produce a source package for https://github.com/colored-console/colored-console, we can use it to wrap up colour management for us.)
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you are right, i think i messed it up at some point (look at the screenshot, it was ok) |
||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| using System.Collections.Generic; | ||
| using System.Linq; | ||
| using Moq; | ||
| using ScriptCs.Contracts; | ||
| using ScriptCs.ReplCommands; | ||
| using Xunit; | ||
|
|
||
| namespace ScriptCs.Tests.ReplCommands | ||
| { | ||
| public class ScriptPacksCommandTests | ||
| { | ||
| public class CommandNameProperty | ||
| { | ||
| [Fact] | ||
| public void ReturnsScriptPacks() | ||
| { | ||
| // act | ||
| var cmd = new ScriptPacksCommand(new Mock<IConsole>().Object); | ||
|
|
||
| // assert | ||
| Assert.Equal("scriptpacks", cmd.CommandName); | ||
| } | ||
| } | ||
|
|
||
| public class ExecuteMethod | ||
| { | ||
| [Fact] | ||
| public void ShouldExitIfThereAreNoScriptPacks() | ||
| { | ||
| // arrange | ||
| var console = new Mock<IConsole>(); | ||
| var repl = new Mock<IRepl>(); | ||
| var scriptPackSession = new Mock<ScriptPackSession>(Enumerable.Empty<IScriptPack>(), new string[0]); | ||
|
|
||
| scriptPackSession.Setup(x => x.Contexts).Returns((IEnumerable<IScriptPackContext>) null); | ||
| repl.Setup(x => x.ScriptPackSession).Returns(scriptPackSession.Object); | ||
|
|
||
| var cmd = new ScriptPacksCommand(console.Object); | ||
|
|
||
| // act | ||
| cmd.Execute(repl.Object, null); | ||
|
|
||
| // assert | ||
| console.Verify(x => x.WriteLine("There are no script packs available in this REPL session")); | ||
| } | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line should be moved down to inside the conditional, just before writing out the message to say there are no script packs. (See further comment below).