tonerdo / readline

A Pure C# GNU-Readline like library for .NET/.NET Core
MIT License
810 stars 77 forks source link

AutoComplete: Index was outside the bounds of the array. #3

Closed gitchomik closed 7 years ago

gitchomik commented 7 years ago

There is a exception in line

https://github.com/tsolarin/readline/blob/master/src/ReadLine/KeyHandler.cs#L137

Unhandled Exception: System.IndexOutOfRangeException: Index was outside the bounds of the array.
   at System.KeyHandler.AutoComplete() in /app/src/ReadLine/KeyHandler.cs:line 137
   at System.KeyHandler.<>c__DisplayClass31_0.<.ctor>b__3() in /app/src/ReadLine/KeyHandler.cs:line 234
   at System.KeyHandler.Handle(ConsoleKeyInfo keyInfo) in /app/src/ReadLine/KeyHandler.cs:line 250
   at System.ReadLine.Read(String prompt) in /app/src/ReadLine/ReadLine.cs:line 28
   at ConsoleApplication.Program.Main(String[] args) in /app/src/ReadLine.Demo/Program.cs:line 27
using System;

namespace ConsoleApplication
{
    public class Program
    {
        public static void Main(string[] args)
        {
            Console.WriteLine("ReadLine Library Demo");
            Console.WriteLine("---------------------");
            Console.WriteLine();

            string[] history = new string[] { "ls -a", "dotnet run", "git init" };
            ReadLine.AddHistory(history);

            ReadLine.AutoCompletionHandler = (t, s) =>
            {
                if (t.StartsWith("ab"))
                    return new string[] { "ab" };
                if (t.StartsWith("a"))
                    return new string[] { "a1", "ab", "acd", "acde", "acdef" };
                return null;
            };

           while (true)
       {
        string input = ReadLine.Read("(prompt)> ");
        Console.Write(input);
            }
        }
    }
}

Scenerio:

  1. press "a"
  2. press TAB (this prints "a1")
  3. clear line
  4. press "ab"
  5. press TAB (throw exception)
gitchomik commented 7 years ago

Still same problem

            ReadLine.AutoCompletionHandler = (t, s) =>
            {
                return new string[0];
            };

Scenerio:

  1. press TAB
  2. press TAB (throw exception)
tonerdo commented 7 years ago

@gitchomik I think it's the same exception but a different cause. Reopening to remind myself to look into it