Resolve() 공개 메소드

public Resolve ( string cmd ) : string[]
cmd string
리턴 string[]
예제 #1
0
        public override string ReadLine(string p, bool isCommand, bool e)
        {
            m_cursorXPosition = 0;
            prompt            = p;
            m_echo            = e;
            int historyLine = m_history.Count;

            SetCursorLeft(0);          // Needed for mono
            System.Console.Write(" "); // Needed for mono

            lock (m_commandLine)
            {
                m_cursorYPosition = System.Console.CursorTop;
                m_commandLine.Remove(0, m_commandLine.Length);
            }

            while (true)
            {
                Show();

                ConsoleKeyInfo key = System.Console.ReadKey(true);

                if ((key.Modifiers & ConsoleModifiers.Control) != 0 && key.Key == ConsoleKey.C)
                {
                    System.Console.Write(Environment.NewLine);
                    LocalCancelKeyPressed();
                    return(string.Empty);
                }
                char enteredChar = key.KeyChar;

                if (!Char.IsControl(enteredChar))
                {
                    if (m_cursorXPosition >= 318)
                    {
                        continue;
                    }

                    if (enteredChar == '?' && isCommand)
                    {
                        if (ContextHelp())
                        {
                            continue;
                        }
                    }

                    m_commandLine.Insert(m_cursorXPosition, enteredChar);
                    m_cursorXPosition++;
                }
                else
                {
                    switch (key.Key)
                    {
                    case ConsoleKey.Backspace:
                        if (m_cursorXPosition == 0)
                        {
                            break;
                        }
                        m_commandLine.Remove(m_cursorXPosition - 1, 1);
                        m_cursorXPosition--;

                        SetCursorLeft(0);
                        m_cursorYPosition = SetCursorTop(m_cursorYPosition);

                        if (m_echo)
                        {
                            System.Console.Write("{0}{1} ", prompt, m_commandLine);
                        }
                        else
                        {
                            System.Console.Write("{0}", prompt);
                        }

                        break;

                    case ConsoleKey.Delete:
                        if (m_cursorXPosition == m_commandLine.Length)
                        {
                            break;
                        }

                        m_commandLine.Remove(m_cursorXPosition, 1);

                        SetCursorLeft(0);
                        m_cursorYPosition = SetCursorTop(m_cursorYPosition);

                        if (m_echo)
                        {
                            System.Console.Write("{0}{1} ", prompt, m_commandLine);
                        }
                        else
                        {
                            System.Console.Write("{0}", prompt);
                        }

                        break;

                    case ConsoleKey.End:
                        m_cursorXPosition = m_commandLine.Length;
                        break;

                    case ConsoleKey.Home:
                        m_cursorXPosition = 0;
                        break;

                    case ConsoleKey.UpArrow:
                        if (historyLine < 1)
                        {
                            break;
                        }
                        historyLine--;
                        LockOutput();
                        m_commandLine.Remove(0, m_commandLine.Length);
                        m_commandLine.Append(m_history[historyLine]);
                        m_cursorXPosition = m_commandLine.Length;
                        UnlockOutput();
                        break;

                    case ConsoleKey.DownArrow:
                        if (historyLine >= m_history.Count)
                        {
                            break;
                        }
                        historyLine++;
                        LockOutput();
                        if (historyLine == m_history.Count)
                        {
                            m_commandLine.Remove(0, m_commandLine.Length);
                        }
                        else
                        {
                            m_commandLine.Remove(0, m_commandLine.Length);
                            m_commandLine.Append(m_history[historyLine]);
                        }
                        m_cursorXPosition = m_commandLine.Length;
                        UnlockOutput();
                        break;

                    case ConsoleKey.LeftArrow:
                        if (m_cursorXPosition > 0)
                        {
                            m_cursorXPosition--;
                        }
                        break;

                    case ConsoleKey.RightArrow:
                        if (m_cursorXPosition < m_commandLine.Length)
                        {
                            m_cursorXPosition++;
                        }
                        break;

                    case ConsoleKey.Enter:
                        SetCursorLeft(0);
                        m_cursorYPosition = SetCursorTop(m_cursorYPosition);

                        System.Console.WriteLine();
                        //Show();

                        lock (m_commandLine)
                        {
                            m_cursorYPosition = -1;
                        }

                        string commandLine = m_commandLine.ToString();

                        if (isCommand)
                        {
                            string[] cmd = Commands.Resolve(Parser.Parse(commandLine));

                            if (cmd.Length != 0)
                            {
                                int index;

                                for (index = 0; index < cmd.Length; index++)
                                {
                                    if (cmd[index].Contains(" "))
                                    {
                                        cmd[index] = "\"" + cmd[index] + "\"";
                                    }
                                }
                                AddToHistory(String.Join(" ", cmd));
                                return(String.Empty);
                            }
                        }

                        // If we're not echoing to screen (e.g. a password) then we probably don't want it in history
                        if (m_echo && commandLine != "")
                        {
                            AddToHistory(commandLine);
                        }

                        return(commandLine);

                    default:
                        break;
                    }
                }
            }
        }
예제 #2
0
        public override string ReadLine(string p, bool isCommand, bool e)
        {
            h      = 1;
            cp     = 0;
            prompt = p;
            echo   = e;
            int historyLine = history.Count;

            SetCursorLeft(0);          // Needed for mono
            System.Console.Write(" "); // Needed for mono

            lock (cmdline)
            {
                y = System.Console.CursorTop;
                cmdline.Remove(0, cmdline.Length);
            }

            while (true)
            {
                Show();

                ConsoleKeyInfo key = System.Console.ReadKey(true);
                char           c   = key.KeyChar;

                if (!Char.IsControl(c))
                {
                    if (cp >= 318)
                    {
                        continue;
                    }

                    if (c == '?' && isCommand)
                    {
                        if (ContextHelp())
                        {
                            continue;
                        }
                    }

                    cmdline.Insert(cp, c);
                    cp++;
                }
                else
                {
                    switch (key.Key)
                    {
                    case ConsoleKey.Backspace:
                        if (cp == 0)
                        {
                            break;
                        }
                        cmdline.Remove(cp - 1, 1);
                        cp--;

                        SetCursorLeft(0);
                        y = SetCursorTop(y);

                        System.Console.Write("{0}{1} ", prompt, cmdline);

                        break;

                    case ConsoleKey.End:
                        cp = cmdline.Length;
                        break;

                    case ConsoleKey.Home:
                        cp = 0;
                        break;

                    case ConsoleKey.UpArrow:
                        if (historyLine < 1)
                        {
                            break;
                        }
                        historyLine--;
                        LockOutput();
                        cmdline.Remove(0, cmdline.Length);
                        cmdline.Append(history[historyLine]);
                        cp = cmdline.Length;
                        UnlockOutput();
                        break;

                    case ConsoleKey.DownArrow:
                        if (historyLine >= history.Count)
                        {
                            break;
                        }
                        historyLine++;
                        LockOutput();
                        if (historyLine == history.Count)
                        {
                            cmdline.Remove(0, cmdline.Length);
                        }
                        else
                        {
                            cmdline.Remove(0, cmdline.Length);
                            cmdline.Append(history[historyLine]);
                        }
                        cp = cmdline.Length;
                        UnlockOutput();
                        break;

                    case ConsoleKey.LeftArrow:
                        if (cp > 0)
                        {
                            cp--;
                        }
                        break;

                    case ConsoleKey.RightArrow:
                        if (cp < cmdline.Length)
                        {
                            cp++;
                        }
                        break;

                    case ConsoleKey.Enter:
                        SetCursorLeft(0);
                        y = SetCursorTop(y);

                        System.Console.WriteLine();
                        //Show();

                        lock (cmdline)
                        {
                            y = -1;
                        }

                        string commandLine = cmdline.ToString();

                        if (isCommand)
                        {
                            string[] cmd = Commands.Resolve(Parser.Parse(commandLine));

                            if (cmd.Length != 0)
                            {
                                int i;

                                for (i = 0; i < cmd.Length; i++)
                                {
                                    if (cmd[i].Contains(" "))
                                    {
                                        cmd[i] = "\"" + cmd[i] + "\"";
                                    }
                                }
                                AddToHistory(String.Join(" ", cmd));
                                return(String.Empty);
                            }
                        }

                        // If we're not echoing to screen (e.g. a password) then we probably don't want it in history
                        if (echo && commandLine != "")
                        {
                            AddToHistory(commandLine);
                        }

                        return(commandLine);

                    default:
                        break;
                    }
                }
            }
        }
예제 #3
0
 public void RunCommand(string cmd)
 {
     string[] parts = Parser.Parse(cmd);
     Commands.Resolve(parts);
 }
예제 #4
0
        public override string ReadLine(string p, bool isCommand, bool e)
        {
            // Output the prompt an prepare to wait. This
            // is called on a dedicated console thread and
            // needs to be synchronous. Old architecture but
            // not worth upgrading.
            if (isCommand)
            {
                m_expectingInput   = true;
                m_expectingCommand = true;
                Output(p, String.Empty, true, true, false);
                m_lastPromptUsed = p;
            }
            else
            {
                m_expectingInput = true;
                Output(p, String.Empty, true, false, false);
            }


            // Here is where we wait for the user to input something.
            m_DataEvent.WaitOne();

            string cmdinput;

            // Check for empty input. Read input if not empty.
            lock (m_InputData)
            {
                if (m_InputData.Count == 0)
                {
                    m_DataEvent.Reset();
                    m_expectingInput   = false;
                    m_expectingCommand = false;

                    return("");
                }

                cmdinput = m_InputData[0];
                m_InputData.RemoveAt(0);
                if (m_InputData.Count == 0)
                {
                    m_DataEvent.Reset();
                }
            }

            m_expectingInput   = false;
            m_expectingCommand = false;

            // Echo to all the other users what we have done. This
            // will also go to ourselves.
            Output(cmdinput, String.Empty, false, false, true);

            // If this is a command, we need to resolve and execute it.
            if (isCommand)
            {
                // This call will actually execute the command and create
                // any output associated with it. The core just gets an
                // empty string so it will call again immediately.
                string[] cmd = Commands.Resolve(Parser.Parse(cmdinput));

                if (cmd.Length != 0)
                {
                    int i;

                    for (i = 0; i < cmd.Length; i++)
                    {
                        if (cmd[i].Contains(" "))
                        {
                            cmd[i] = "\"" + cmd[i] + "\"";
                        }
                    }
                    return(String.Empty);
                }
            }

            // Return the raw input string if not a command.
            return(cmdinput);
        }