private void KeyUpHandler(object sender, System.Windows.Forms.KeyEventArgs e)
{
// if enter is pressed we should process the command
if (e.KeyData == Keys.Enter)
{
String command = commandTextBox.Text;
commands.Add(command);
commandMarker = commands.Count;
commandTextBox.Clear();
// echo the command
WriteLine(Prompt + command);
lock(this)
{
latestLine = command;
newLineAvailable = true;
}
}
// if up is pressed return the previous command in the list in the usual way
if (e.KeyData == Keys.Up)
{
commandMarker--;
if (commandMarker<0) commandMarker = 0;
commandTextBox.Clear();
commandTextBox.Text= commands[commandMarker];
commandTextBox.Select(commandTextBox.Text.Length,0);
}
// if down is pressed return the next command in the usual way
if (e.KeyData == Keys.Down)
{
commandMarker++;
if (commandMarker > commands.Count) commandMarker = commands.Count;
commandTextBox.Clear();
if (commandMarker == commands.Count)
{
}
else
{
commandTextBox.Text = commands[commandMarker];
commandTextBox.Select(commandTextBox.Text.Length, 0);
}
}
// tab attempts to autocomplete the command
if (e.KeyData == Keys.Tab)
{
String[] suggestions = manager.Processor.GetCommandSuggestions(commandTextBox.Text);
if (suggestions == null) return;
if (suggestions.Length == 1)
{
commandTextBox.Text = suggestions[0] + " ";
commandTextBox.SelectionStart = commandTextBox.Text.Length;
return;
}
StringBuilder sb = new StringBuilder();
foreach (String s in suggestions) sb.Append(s + "\t");
sb.Append(Environment.NewLine);
WriteLine(sb.ToString());
}
// escape clears the current text
if (e.KeyData == Keys.Escape) commandTextBox.Clear();
}