Beispiel #1
0
        //
        // The EditLoop: One loop for each key pressed!
        //
        private string EditLoop(IQueryCompiledError queryCompiledError)
        {
            while (true)
            {
                //
                // Fill m_UndoRedoStates
                //
                m_UndoRedoStates.Append(m_CurrentState);

                //
                // Re-write the query each time a key is pressed
                //
                m_ConsoleWriter.Rewrite(m_CurrentState);

                // Eventually show errors
                if (queryCompiledError != null)
                {
                    // Show errors once...
                    m_ConsoleWriter.ShowQueryCompiledErrors(m_CurrentState, queryCompiledError);
                    // ... and then set queryCompiledError to null to avoid showing them anymore
                    queryCompiledError = null;
                }

                //
                // ReadKey!
                //
                var consoleKeyInfo = Console.ReadKey();

                //
                // Handle special console key
                //
                switch (consoleKeyInfo.Key)
                {
                case ConsoleKey.F5:                          // F5 --> Run the query!;
                    Console.CursorVisible = false;
                    m_ConsoleWriter.Rewrite(m_CurrentState); // <-- need to rewrite the query, else the char where the cursor was is hidden!
                    m_ConsoleWriter.SetCursorPosition(0, m_CurrentState.Lines.Count);
                    Console.CursorLeft    = 0;
                    Console.CursorVisible = true;
                    m_AlreadyEditedQueries.AppendButDontClearNext(m_CurrentState.QueryString);
                    return(m_CurrentState.QueryString);

                case ConsoleKey.Escape:
                    return(null);

                case ConsoleKey.PageUp:
                    m_ConsoleWriter.ClearQueryEdit(m_CurrentState);
                    m_CurrentState = new State(m_AlreadyEditedQueries.GetPrevious(), 0, 0, Location.Null);
                    m_UndoRedoStates.Clear(m_CurrentState);
                    continue;

                case ConsoleKey.PageDown:
                    m_ConsoleWriter.ClearQueryEdit(m_CurrentState);
                    m_CurrentState = new State(m_AlreadyEditedQueries.GetNext(), 0, 0, Location.Null);
                    m_UndoRedoStates.Clear(m_CurrentState);
                    continue;
                }

                //
                // Handle the key inputed with the appropriate keyHandler
                //
                foreach (var keyHandler in m_KeyHandlers)
                {
                    if (!keyHandler.IsHandlerFor(consoleKeyInfo))
                    {
                        continue;
                    }
                    m_CurrentState = keyHandler.Handle(consoleKeyInfo, m_CurrentState);
                    break;
                }
                continue;
            }
        }