コード例 #1
0
        public void InsertCharsAtShallProduceCorrectStrings(string entry, int index, string textToInsert, string expectedResult)
        {
            var testedObj = new VirtualEntryLine(new Mock <IConsole>().Object, new FakeClipBoard(), new ConsoleFontColor(Color.AliceBlue, Color.AntiqueWhite));

            char[] buffer = new char[entry.Length + textToInsert.Length];
            entry.ToCharArray().CopyTo(buffer, 0);
            char[] insertBuffer = textToInsert.ToCharArray();
            int    len          = entry.Length;

            testedObj.InsertCharsAt(buffer, index, insertBuffer, ref len);

            string result = new string(buffer, 0, len);

            result.ShouldBe(expectedResult);
        }
コード例 #2
0
        public void RemoveCharsAtShallProduceCorrectStrings(string entry, int index, int removeQty, string expectedResult)
        {
            var testedObj = new VirtualEntryLine(new Mock <IConsole>().Object, new FakeClipBoard(), new ConsoleFontColor(Color.AliceBlue, Color.AntiqueWhite));

            char[] buffer = entry.ToCharArray();
            int    len    = entry.Length;

            testedObj.RemoveCharsAt(buffer, index, removeQty, ref len);

            len.ShouldBe(expectedResult.Length);

            string result = new string(buffer, 0, len);

            result.ShouldBe(expectedResult);
        }
コード例 #3
0
ファイル: CommandEngine.cs プロジェクト: ObscureWare/Console
        // NO default public constructor - by design -> use builder
        internal CommandEngine(CommandManager commandManager, ICommandParserOptions options, CommandEngineStyles styles, HelpPrinter printHelper, IConsole console, IClipboard clipboard)
        {
            commandManager.Requires(nameof(commandManager)).IsNotNull();
            options.Requires(nameof(options)).IsNotNull();
            styles.Requires(nameof(styles)).IsNotNull();
            printHelper.Requires(nameof(printHelper)).IsNotNull();
            console.Requires(nameof(console)).IsNotNull();
            clipboard.Requires(nameof(clipboard)).IsNotNull();

            this._commandManager        = commandManager;
            this._autoCompletionManager = new CommandAutoCompletionProvider(this._commandManager);
            this._virtualLine           = new VirtualEntryLine(console, clipboard, styles.Default);
            this._console       = console;
            this._options       = options;
            this._styles        = styles;
            this._helpPrinter   = printHelper;
            this._outputManager = new OutputManager(this._console, this._styles, this._options.UiCulture);

            // TODO: check option before displaying this message
            // this._console.WriteLine(styles.Default, "Initializing ObscureWare's command engine...");
        }
コード例 #4
0
        // TODO: write simulation console to automatically test complex printing functions results (content only, no color abstracting)

        private static void SimulateConsole(IConsole console)
        {
            console.WriteLine("Starting command line simulator (entry line only, no real commands). Type 'exit' `command` to stop it.");

            var promptConsoleColor = new ConsoleFontColor(Color.LightSkyBlue, Color.Black);
            var cmdColor           = new ConsoleFontColor(Color.LightGray, Color.Black);
            var retypeColor        = new ConsoleFontColor(Color.Lime, Color.Black);

            VirtualEntryLine cmdSimulator = new VirtualEntryLine(console, new FakeClipBoard(), cmdColor);

            var    fakeAutocompleter = new TestAutoCompleter("abcd", "aabbdd", "nbbdbd", "sdsdsds", "sddsdssfdf", "abc");
            string cmd = "";

            while (!string.Equals(cmd, "EXIT", StringComparison.OrdinalIgnoreCase))
            {
                console.WriteText(promptConsoleColor, "c:\\");
                cmd = cmdSimulator.GetUserEntry(fakeAutocompleter);
                console.WriteLine();
                console.WriteLine(retypeColor, cmd);
                console.WriteLine();
            }
        }
コード例 #5
0
        public void Run(IConsole console)
        {
            console.WriteLine("Starting command line simulator (entry line only, no real commands). Type 'exit' `command` to stop it.");
            console.WriteLine("There are also some fake auto-completion suggestions starting with 'a*' and 's'. Use (Shit)+Tab to test them.");

            var promptConsoleColor = new ConsoleFontColor(Color.LightSkyBlue, Color.Black);
            var cmdColor           = new ConsoleFontColor(Color.LightGray, Color.Black);
            var retypeColor        = new ConsoleFontColor(Color.Lime, Color.Black);

            VirtualEntryLine cmdSimulator = new VirtualEntryLine(console, new FakeClipBoard(), cmdColor);

            var fakeAutocompleter = new TestingAutoCompleter("abcd", "aabbdd", "asddhhhs", "nbbdbd", "sdsdsds", "sddsdssfdf", "abc", "sdessse");
            // TODO: replace with dynamic auto-completer that does not ignore letter already enetered
            string cmd = "";

            while (!string.Equals(cmd, "EXIT", StringComparison.OrdinalIgnoreCase))
            {
                console.WriteText(promptConsoleColor, "c:\\");
                cmd = cmdSimulator.GetUserEntry(fakeAutocompleter);
                console.WriteLine();
                console.WriteLine(retypeColor, cmd);
                console.WriteLine();
            }
        }
コード例 #6
0
        public void CalculateCursorPositionForLineIndexShouldCalculateCorrectPositions(int xStart, int yStart, int lineLength, int targetIndex, int xExpected, int yExpected)
        {
            var testedObj = new VirtualEntryLine(new Mock <IConsole>().Object, new FakeClipBoard(), new ConsoleFontColor(Color.AliceBlue, Color.AntiqueWhite));

            testedObj.CalculateCursorPositionForLineIndex(new Point(xStart, yStart), lineLength, targetIndex).ShouldBe(new Point(xExpected, yExpected));
        }
コード例 #7
0
        public void CalculatePositionInLineShouldCalculateCorrectPositions(int xStart, int yStart, int xCurrent, int yCurrent, int lineLength, int expected)
        {
            var testedObj = new VirtualEntryLine(new Mock <IConsole>().Object, new FakeClipBoard(), new ConsoleFontColor(Color.AliceBlue, Color.AntiqueWhite));

            testedObj.CalculatePositionInLine(new Point(xStart, yStart), new Point(xCurrent, yCurrent), lineLength).ShouldBe(expected);
        }