示例#1
0
        protected void AutoComplete()
        {
            string complete = string.Empty;
            var    command  = FieldText.ToString();

            string[] cmd;
            if (!Util.TrySplitCommand(command, out cmd))
            {
                return;
            }

            if (cmd.Length > 1)
            {
                Command result;
                if (CommandSet.TryGetValue(cmd [0], out result))
                {
                    complete = result.AutoComplete(command);
                }
            }
            else
            {
                foreach (var id in CommandSet.Keys)
                {
                    if (id.StartsWith(command))
                    {
                        complete = id.Remove(0, command.Length);
                    }
                }
            }

            AddText(complete);
            Console.Write(complete);
        }
示例#2
0
        protected void ProcessCommand()
        {
            string cmd = FieldText.ToString();

            CommandHistory.Add(cmd);
            Console.WriteLine();
            string cmdId = cmd.ReadToCharOrEnd(' ');

            if (CommandSet.ContainsKey(cmdId))
            {
                var result = RunCommand(FieldText.ToString());
                if (result.Resultcode != 0)
                {
                    Console.WriteLine(result.Message);
                }
            }
            else
            {
                Console.WriteLine("\"{0}\" is not recognized as a command. Try \"help\"", cmdId);
            }
            EndOfInput = true;
        }
示例#3
0
        protected virtual void RegisterBaseKeys()
        {
            FunctionKeys[new ConsoleKeyInfo('\0', ConsoleKey.RightArrow, false, false, false)] = () => MoveCursor();
            FunctionKeys[new ConsoleKeyInfo('\0', ConsoleKey.RightArrow, false, false, true)]  = () => {
                MoveCursor(FieldText.ToString().Substring(CurrentChar)
                           .TakeWhile(c => !char.IsWhiteSpace(c)).Count() + 1);
            };

            FunctionKeys[new ConsoleKeyInfo('\0', ConsoleKey.LeftArrow, false, false, false)] = () => MoveCursor(-1);
            FunctionKeys[new ConsoleKeyInfo('\0', ConsoleKey.LeftArrow, false, false, true)]  = () => {
                MoveCursor(-FieldText.ToString().Reverse().Skip(FieldText.Length - CurrentChar + 1)
                           .TakeWhile(c => !char.IsWhiteSpace(c)).Count() - 1);
            };

            FunctionKeys[new ConsoleKeyInfo('\r', ConsoleKey.Enter, false, false, false)] = () => {
                AddText('\n');
                MoveCursor();
            };

            FunctionKeys[new ConsoleKeyInfo('\b', ConsoleKey.Backspace, false, false, false)] = () => {
                if (FieldText.Length == 0 || CurrentChar == 0)
                {
                    return;
                }
                FieldRows[CurrentRow].Remove(CurrentChar - 1, 1);
                SyncBuffer(CurrentRow);
                MoveCursor(-1);
            };

            FunctionKeys[new ConsoleKeyInfo('\0', ConsoleKey.Delete, false, false, false)] = () => {
                if (FieldText.Length == 0 || CurrentChar == FieldText.Length)
                {
                    return;
                }
                ClearBuffer();
                FieldText.Remove(CurrentChar, 1);
            };
        }