コード例 #1
0
ファイル: CommandLoop.cs プロジェクト: dff-solutions/shell.me
 public CommandLoop(Configuration configuration)
 {
     var adapter = new LowLevelToAbstractConsoleAdapter(configuration.Console);
     Console = adapter;
     _commandFactory = configuration.CommandFactory;
     _lockingService = configuration.LockingService;
     _history = configuration.ConsoleHistory;
     InitializeHistory(adapter);
 }
コード例 #2
0
        public void WritesHelloWorld()
        {
            var inputSequence = "Hello World".ToInputSequence();
            var lowLevelConsole = new LowLevelTestConsole(inputSequence);
            var adapter = new LowLevelToAbstractConsoleAdapter(lowLevelConsole) { Prompt = "$ " };

            adapter.ReadUntilSequenceIsOver(inputSequence);

            Assert.AreEqual("$ Hello World", lowLevelConsole.ReadInLineFromTo(0,0,12));
        }
コード例 #3
0
        public void WritesPrompt()
        {
            var inputSequence = " ".ToInputSequence();
            var lowLevelConsole = new LowLevelTestConsole(inputSequence);
            var adapter = new LowLevelToAbstractConsoleAdapter(lowLevelConsole) {Prompt = "$ "};

            adapter.ReadUntilSequenceIsOver(inputSequence);
            var written = lowLevelConsole.ReadCharacterAt(0, 0);
            Assert.AreEqual('$',written);
        }
コード例 #4
0
        public void BreaksLineOnTheRightCharacter()
        {
            var inputSequence = "Hello this is shell.me. We are testing the new LowLevelConsole, which gives us great power!".ToInputSequence();
            var lowLevelConsole = new LowLevelTestConsole(inputSequence);
            var adapter = new LowLevelToAbstractConsoleAdapter(lowLevelConsole) { Prompt = "(S) " };

            adapter.ReadUntilSequenceIsOver(inputSequence);

            Assert.AreEqual("(S) Hello this is shell.me. We are testing the new LowLevelConsole, which gives ", lowLevelConsole.ReadInLineFromTo(0, 0, 79));
            Assert.AreEqual("us great power!", lowLevelConsole.ReadInLineFromTo(1, 0, 14));
        }
コード例 #5
0
        public void CursorMovesLeftUntilItHitsThePrompt()
        {
            var inputSequence = "Hello"
                .ToInputSequence()
                .AddLeftArrowHit(5);

            var lowLevelConsole = new LowLevelTestConsole(inputSequence);
            var adapter = new LowLevelToAbstractConsoleAdapter(lowLevelConsole) { Prompt = "(S) " };

            adapter.ReadUntilSequenceIsOver(inputSequence);

            Assert.AreEqual("(S) Hello", lowLevelConsole.ReadInLineFromTo(0, 0, 8));
            Assert.AreEqual(4, lowLevelConsole.CursorLeft);
            Assert.AreEqual(0, lowLevelConsole.CursorTop);
        }
コード例 #6
0
        public void BackspaceJumpsLineUpAndLetsUsWriteAgain()
        {
            var inputSequence = "Hello this is shell.me. We are testing the new LowLevelConsole, which gives us great power!"
                .ToInputSequence()
                .AddBackspaceHit(21)
                .AddInputSequence("rocks!");

            var lowLevelConsole = new LowLevelTestConsole(inputSequence);
            var adapter = new LowLevelToAbstractConsoleAdapter(lowLevelConsole) { Prompt = "(S) " };

            adapter.ReadUntilSequenceIsOver(inputSequence);

            Assert.AreEqual("(S) Hello this is shell.me. We are testing the new LowLevelConsole, which rocks!", lowLevelConsole.ReadInLineFromTo(0, 0, 79));
            //We are just making sure that there is nothing left on the second line
            Assert.AreEqual("                                                                                ", lowLevelConsole.ReadInLineFromTo(1, 0, 79));
        }
コード例 #7
0
ファイル: CommandLoop.cs プロジェクト: dff-solutions/shell.me
        private void InitializeHistory(LowLevelToAbstractConsoleAdapter adapter)
        {
            var keyMap = new Dictionary<ConsoleKey, Func<HistoryEntry>>
                             {
                                 { ConsoleKey.UpArrow, () => _history.GetNextEntry() },
                                 { ConsoleKey.DownArrow, () => _history.GetPreviousEntry() }
                             };

            adapter.KeyStrokes
                .Select(keyInfo => keyInfo.Key)
                .Where(key => key == ConsoleKey.UpArrow || key == ConsoleKey.DownArrow)
                .Select(key => keyMap[key])
                .Subscribe(func =>
                               {
                                   adapter.EraseCurrentLine();
                                   var historyEntry = func();

                                   if (historyEntry != null)
                                   {
                                       adapter.Write(historyEntry.Value);
                                   }
                               });
        }
コード例 #8
0
        public void CursorCanNotMoveAheadTheWriting()
        {
            var inputSequence = "Hello"
                .ToInputSequence()
                .AddRightArrowHit(5);

            var lowLevelConsole = new LowLevelTestConsole(inputSequence);
            var adapter = new LowLevelToAbstractConsoleAdapter(lowLevelConsole) { Prompt = "(S) " };

            adapter.ReadUntilSequenceIsOver(inputSequence);

            Assert.AreEqual("(S) Hello", lowLevelConsole.ReadInLineFromTo(0, 0, 8));
            Assert.AreEqual(9, lowLevelConsole.CursorLeft);
            Assert.AreEqual(0, lowLevelConsole.CursorTop);
        }
コード例 #9
0
        public void WriteLineWorks()
        {

            var lowLevelConsole = new LowLevelTestConsole();
            var adapter = new LowLevelToAbstractConsoleAdapter(lowLevelConsole) { Prompt = "(S) " };

            adapter.WriteLine("Hello World");
            adapter.WriteLine("Hello World");

            Assert.AreEqual("Hello World", lowLevelConsole.ReadInLineFromTo(0, 0, 10));
            Assert.AreEqual("Hello World", lowLevelConsole.ReadInLineFromTo(1, 0, 10));
            
            Assert.AreEqual(0, lowLevelConsole.CursorLeft);
        }
コード例 #10
0
        public void ErasesCurrentLineAndResetsCursor()
        {
            var inputSequence = "Hello".ToInputSequence();

            var lowLevelConsole = new LowLevelTestConsole(inputSequence);
            var adapter = new LowLevelToAbstractConsoleAdapter(lowLevelConsole) { Prompt = "(S) " };

            adapter.ReadUntilSequenceIsOver(inputSequence);

            Assert.AreEqual("(S) Hello", lowLevelConsole.ReadInLineFromTo(0, 0, 8));
            Assert.AreEqual(9, lowLevelConsole.CursorLeft);

            adapter.EraseCurrentLine();

            Assert.AreEqual("(S)      ", lowLevelConsole.ReadInLineFromTo(0, 0, 8));
            Assert.AreEqual(4, lowLevelConsole.CursorLeft);
        }
コード例 #11
0
        public void WritesMovesCursorBeforeWritingAndInsertsAnotherWord()
        {
            var inputSequence = "World"
                .ToInputSequence()
                .AddLeftArrowHit(5)
                .AddInputSequence("Hello ");

            var lowLevelConsole = new LowLevelTestConsole(inputSequence);
            var adapter = new LowLevelToAbstractConsoleAdapter(lowLevelConsole) { Prompt = "(S) " };

            adapter.ReadUntilSequenceIsOver(inputSequence);

            Assert.AreEqual("(S) Hello World", lowLevelConsole.ReadInLineFromTo(0, 0, 14));
            Assert.AreEqual(10, lowLevelConsole.CursorLeft);
        }