Added TAB autocomplete

Now handles TAB keypresses and ask the server for an autocompletion,
just like a vanilla client does.
This commit is contained in:
ORelio 2013-08-06 12:25:09 +02:00
parent d1770ebb02
commit 88105d30ad
3 changed files with 53 additions and 2 deletions

View file

@ -13,6 +13,8 @@ namespace MinecraftClient
public static class ConsoleIO
{
public static void Reset() { if (reading) { reading = false; Console.Write("\b \b"); } }
public static void SetAutoCompleteEngine(IAutoComplete engine) { autocomplete_engine = engine; }
private static IAutoComplete autocomplete_engine;
private static LinkedList<string> previous = new LinkedList<string>();
private static string buffer = "";
private static string buffer2 = "";
@ -87,6 +89,20 @@ namespace MinecraftClient
}
break;
case ConsoleKey.Tab:
if (autocomplete_engine != null && buffer.Length > 0)
{
string[] tmp = buffer.Split(' ');
if (tmp.Length > 0)
{
string word_tocomplete = tmp[tmp.Length - 1];
string word_autocomplete = autocomplete_engine.AutoComplete(word_tocomplete);
if (!String.IsNullOrEmpty(word_autocomplete) && word_autocomplete != word_tocomplete)
{
while (buffer.Length > 0 && buffer[buffer.Length - 1] != ' ') { RemoveOneChar(); }
foreach (char c in word_autocomplete) { AddChar(c); }
}
}
}
break;
default:
AddChar(k.KeyChar);
@ -215,4 +231,14 @@ namespace MinecraftClient
}
#endregion
}
/// <summary>
/// Interface for TAB autocompletion
/// Allows to use any object which has an AutoComplete() method using the IAutocomplete interface
/// </summary>
public interface IAutoComplete
{
string AutoComplete(string BehindCursor);
}
}