Пример #1
0
        static void Main()
        {
            LineEditor le = new LineEditor(null);
            string     s;

            while ((s = le.Edit("shell> ", "")) != null)
            {
                Console.WriteLine("----> [{0}]", s);
            }
        }
Пример #2
0
        public void StartLineEditor()
        {
            LineEditor le = new LineEditor("LineEditor", 50);
            le.AutoCompleteEvent = (string text, int pos) =>
            {
                //text = text.ToLower();
                string token = null;
                for (int i = pos - 1; i >= 0; i--)
                {
                    if (Char.IsWhiteSpace(text[i]))
                    {
                        token = text.Substring(i + 1, pos - i - 1);
                        break;
                    }
                    else if (i == 0)
                        token = text.Substring(0, pos);
                }
                List<string> results = new List<string>();
                if (token == null)
                {
                    token = string.Empty;
                    results.AddRange(CommandMatcher.AutoComplete.Select(x => x.Path).ToArray());
                }
                else
                {
                    string[] completePaths = CommandMatcher.AutoComplete
                        .Where(x => x.Path.Length > pos)
                        .Select(x => x.Path.Substring(pos - token.Length))
                        .ToArray();
                    for (int i = 0; i < completePaths.Length; i++)
                    {
                        if (completePaths[i].StartsWith(token))
                        {
                            string result = completePaths[i];
                            results.Add(result.Substring(token.Length, result.Length - token.Length));
                        }
                    }

                }
                return new LineEditor.Completion(token, results.ToArray());
            };
            string s;
            while ((s = le.Edit("> ", "")) != null)
            {
                if (new[] { "exit", "quit", "bye", "q", "e" }.Contains(s)) break;
                CommandMatcher.CallAction(s);
            }
        }
Пример #3
0
		static void Main ()
		{
			LineEditor le = new LineEditor (null);
			string s;
			
			while ((s = le.Edit ("shell> ", "")) != null){
				Console.WriteLine ("----> [{0}]", s);
			}
		}