public async Task ReadLine_StartWritingWord_NonWordCharacterShouldCloseCompletion() { var spacebarIsNotCommitCharacterCfg = new PromptConfiguration( keyBindings: new KeyBindings( commitCompletion: new[] { new KeyPressPattern(Enter) })); var console = ConsoleStub.NewConsole(); console.StubInput( $"ab", $"{Spacebar}", //this should close completion list (without insertion) and write space $"{Enter}"); var prompt = ConfigurePrompt(console, completions: new[] { "abcd" }, configuration: spacebarIsNotCommitCharacterCfg); var result = await prompt.ReadLineAsync(); Assert.True(result.IsSuccess); Assert.Equal("ab ", result.Text); //------------------------------------------ var spacebarIsCommitCharacterCfg = new PromptConfiguration( keyBindings: new KeyBindings( commitCompletion: new[] { new KeyPressPattern(Spacebar) })); console = ConsoleStub.NewConsole(); console.StubInput( $"ab", $"{Spacebar}", //this should insert completion item and write space $"{Enter}"); prompt = ConfigurePrompt(console, completions: new[] { "abcd" }, configuration: spacebarIsCommitCharacterCfg); result = await prompt.ReadLineAsync(); Assert.True(result.IsSuccess); Assert.Equal("abcd ", result.Text); }
public CompletionPane( CodePane codePane, IPromptCallbacks promptCallbacks, PromptConfiguration configuration) { this.codePane = codePane; this.promptCallbacks = promptCallbacks; this.configuration = configuration; }
public void GetClassInstanceSingleObjectTest() { var config = new PromptConfiguration(); // Scan this file only var data2A = new Data2a(); config.Objects = new object[] { data2A }; var prompt = new Prompt(config); prompt.Run("2aCmd1"); data2A.Name.Should().Be("2aCmd1"); }
public void GetClassInstanceSingleObjectFromInterfaceTest() { var config = new PromptConfiguration(); // Scan this file only var data2C = new Data2C(); config.Objects = new object[] { data2C }; var prompt = new Prompt(config); prompt.Run("2cCmd1"); data2C.Name.Should().Be("2cCmd1"); }
public void GetClassInstanceManyParametersObjectOrderDifferentTest() { var config = new PromptConfiguration(); // Scan this file only var data2A = new Data2a(); var data2B = new Data2b(); config.Objects = new object[] { data2B, data2A }; var prompt = new Prompt(config); prompt.Run("2aCmd1"); data2A.Name.Should().Be("2aCmd1"); }
public void CanDoTest(string promptCmd, string pramText) { CanDoPrompt.MethodRun = CanDoPrompt.MethodValue = "Before Test"; var config = new PromptConfiguration(); // Scan this file only var prompt = new Prompt(config); var cmd = $"{promptCmd} {pramText}".Trim(); prompt.Run(cmd); CanDoPrompt.MethodRun.Should().Be(promptCmd); CanDoPrompt.MethodValue.Should().Be(pramText); }
public void GetClassInstanceKeptNotTest() { var config = new PromptConfiguration(); // Scan this file only var data2A = new Data2a(); config.Objects = new object[] { data2A }; var prompt = new Prompt(config); prompt.Run("2aCmd1"); // 2a Keep Class between Commands data2A.Name.Should().Be("2aCmd1"); data2A.ClassCount.Should().Be(1); prompt.Run("2aCmd1"); data2A.ClassCount.Should().Be(1); data2A.UsageCount.Should().Be(2); }
/// <summary> /// Instantiates a prompt object. This object can be re-used for multiple invocations of <see cref="ReadLineAsync()"/>. /// </summary> /// <param name="persistentHistoryFilepath">The filepath of where to store history entries. If null, persistent history is disabled.</param> /// <param name="callbacks">A collection of callbacks for modifying and intercepting the prompt's behavior</param> /// <param name="console">The implementation of the console to use. This is mainly for ease of unit testing</param> /// <param name="configuration">If null, default configuration is used.</param> public Prompt( string?persistentHistoryFilepath = null, PromptCallbacks?callbacks = null, IConsole?console = null, PromptConfiguration?configuration = null) { this.console = console ?? new SystemConsole(); this.console.InitVirtualTerminalProcessing(); this.configuration = configuration ?? new PromptConfiguration(); this.history = new HistoryLog(persistentHistoryFilepath, this.configuration.KeyBindings); this.cancellationManager = new CancellationManager(this.console); this.clipboard = (console is IConsoleWithClipboard consoleWithClipboard) ? consoleWithClipboard.Clipboard : new Clipboard(); promptCallbacks = callbacks ?? new PromptCallbacks(); this.highlighter = new SyntaxHighlighter(promptCallbacks, PromptConfiguration.HasUserOptedOutFromColor); }
public void GetClassInstanceKeptIsTest() { var config = new PromptConfiguration(); // Scan this file only var data2B = new Data2b(); config.Objects = new object[] { data2B }; var prompt = new Prompt(config); prompt.Run("2bCmd1"); // 2b New Class Instance between Commands data2B.Name.Should().Be("2bCmd1"); data2B.ClassCount.Should().Be(1); data2B.UsageCount.Should().Be(1); prompt.Run("2bCmd1"); data2B.ClassCount.Should().Be(1); // Keep Class Reused between Commands, that same count data2B.UsageCount.Should().Be(2); }
static void Main(string[] args) { Console.WriteLine("Hello World!"); PromptTests.IncludeThisAss(); var tasks = new List <Task>(); var configuration = new PromptConfiguration { ApplicationHelp = "Command Prompt Demo" }; using (var tokenSource = new CancellationTokenSource()) { tasks.Add(Prompt.RunAsync(configuration, tokenSource.Token)); // Add other Tasks i.e. service task // Wait for any of the task to exit, this would indicate that the application is shutting down Task.WaitAny(tasks.ToArray()); } Console.WriteLine("Good Bye World!"); }
public void ChangeToFredFolder() { // Set up Configuration var config = new PromptConfiguration(); // Scan this file only config.PromptPostFix = ">"; var prompt = new Prompt(config); var cmd = $"cd bill"; prompt.Run(cmd); prompt.CurrentFolder.Should().Be("Bill"); cmd = $"cd fred"; prompt.Run(cmd); prompt.CurrentFolder.Should().Be("Fred"); cmd = $"cd .."; prompt.Run(cmd); prompt.CurrentFolder.Should().BeEmpty(); }