void MinecraftServer_TabComplete(object sender, TabCompleteEventArgs e) { if (TabComplete != null) { var eventArgs = new TabCompleteEventArgs(e.Text, e.Client); TabComplete(this, eventArgs); if (eventArgs.Handled) { return; } } // Handle it ourselves string[] matches = new string[0]; if (e.Text.StartsWith("/")) { // Command if (e.Text.Contains(' ')) { // Command parameter var name = e.Text.Substring(1, e.Text.IndexOf(' ') - 1); var text = e.Text.Substring(e.Text.IndexOf(' ') + 1); var command = Command.GetCommand(name); if (command.TabComplete(this, text, out matches)) { e.Text = matches.First(); } else { TabCompleteUsername(e.Text, out matches); } } else { var commands = new List <string>(); foreach (var command in Command.Commands) { commands.Add("/" + command.DefaultCommand); commands.AddRange(command.Aliases.Select(s => "/" + s)); } matches = commands.Where(c => c.StartsWith(e.Text, StringComparison.OrdinalIgnoreCase)).ToArray(); if (matches.Length == 1) { e.Text = "/" + matches.First(); } } } else { TabCompleteUsername(e.Text, out matches); } if (matches.Length == 1) { e.Handled = true; e.Text = matches[0]; } else { e.Client.SendChat(string.Join(", ", matches)); } }
protected internal void OnTabComplete(TabCompleteEventArgs e) { if (TabComplete != null) { TabComplete(this, e); } }
public static void TabComplete(MinecraftClient client, MinecraftServer server, IPacket _packet) { var packet = (TabCompletePacket)_packet; var eventArgs = new TabCompleteEventArgs(packet.Text, client); server.OnTabComplete(eventArgs); if (eventArgs.Handled) { packet.Text = eventArgs.Text; client.SendPacket(packet); } }
private void ReadlineOnTabComplete(object sender, TabCompleteEventArgs e) { var buff = ((Readline.Readline)sender).LineBuffer; // Remove preprocessor syntax that the command processor doesn't know about foreach (var pp in PreprocessorStages.OrderBy(s => s.Priority)) { buff = pp.RemovePreprocessorSyntax(buff); } lock (_lock) { var complete = _container.CompleteInput(this, buff).ToArray(); string[] formattedComplete = { }; if (CompletionFormatter != null) { formattedComplete = CompletionFormatter(complete) ?? complete; CompletionFormatter = DefaultCompletionFormatter; } if (ForceCompletionsAsAlternatives) { e.Alternatives = formattedComplete; ForceCompletionsAsAlternatives = false; } else if (complete.Length == 1) { e.Output = formattedComplete.First(); } else if (complete.Length > 1) { var commonPrefix = FindCommonPrefix(complete); if (!string.IsNullOrEmpty(commonPrefix) && !buff.EndsWith(commonPrefix, StringComparison.OrdinalIgnoreCase)) { e.Output = commonPrefix; // Auto-fill as much as possible } else { e.Alternatives = formattedComplete; } } } }
private void ReadlineOnTabComplete(object sender, TabCompleteEventArgs e) { var buff = ((Readline.Readline)sender).LineBuffer; lock (_lock) { var complete = _container.CompleteInput(this, buff).ToArray(); if (complete.Length == 1) { e.Output = complete.First() + " "; } else if (complete.Length > 1) { e.Alternatives = complete; } } }
private void OnTabComplete(object sender, TabCompleteEventArgs e) { try { string completeCommandString = application.PartialLine.Trim(); bool variableExpansion = false; // ok, do we have a variable expansion ? int pos = e.Text.Length - 1; while (pos > 0 && (e.Text[pos] != '$') && Char.IsLetter(e.Text[pos])) { --pos; } // either $... or ${... if ((pos >= 0 && e.Text[pos] == '$')) { variableExpansion = true; } else if ((pos >= 1) && e.Text[pos - 1] == '$' && e.Text[pos] == '{') { variableExpansion = true; --pos; } if (variableExpansion) { if (application is ISettingsHandler) { ApplicationSettings settings = ((ISettingsHandler)application).Settings; if (e.State == 0) { variablePrefix = e.Text.Substring(0, pos); String varname = e.Text.Substring(pos); possibleValues = settings.CompleteUserVariable(varname); } if (possibleValues.MoveNext()) { e.Output = variablePrefix + ((String)possibleValues.Current); } else { possibleValues.Reset(); } } } // the first word.. the command. else if (completeCommandString.Equals(e.Text)) { string text = e.Text.ToLower(); if (e.State == 0) { possibleValues = GetRegisteredCommandNames(text).GetEnumerator(); } while (HasNext(possibleValues)) { String nextKey = (String)possibleValues.Current; if (nextKey == null || nextKey.Length == 0) // don't complete the 'empty' thing. { continue; } if (text.Length < 1) { Command c = (Command)commandMap[nextKey]; if (!c.CommandCompletion) { continue; } if (c.RequiresContext && (application.ActiveContext == null || !application.ActiveContext.IsIsolated)) { continue; } } if (nextKey.StartsWith(text)) { e.Output = nextKey; break; } } } // .. otherwise get completion from the specific command. else { string text = e.Text.ToLower(); if (e.State == 0) { Command cmd = GetCommand(completeCommandString); if (cmd != null) { possibleValues = cmd.Complete(this, completeCommandString, text); } } while (HasNext(possibleValues)) { string key = (string)possibleValues.Current; if (key.ToLower().StartsWith(text)) { e.Output = key; break; } } } } catch (Exception ex) { Application.Error.WriteLine("An error occurred while TAB-completing: {0}", ex.Message); e.Error = true; possibleValues = null; throw; } }
private void OnTabComplete(object sender, TabCompleteEventArgs e) { try { string completeCommandString = application.PartialLine.Trim(); bool variableExpansion = false; // ok, do we have a variable expansion ? int pos = e.Text.Length - 1; while (pos > 0 && (e.Text[pos] != '$') && Char.IsLetter(e.Text[pos])) { --pos; } // either $... or ${... if ((pos >= 0 && e.Text[pos] == '$')) { variableExpansion = true; } else if ((pos >= 1) && e.Text[pos - 1] == '$' && e.Text[pos] == '{') { variableExpansion = true; --pos; } if (variableExpansion) { if (application is ISettingsHandler) { ApplicationSettings settings = ((ISettingsHandler) application).Settings; if (e.State == 0) { variablePrefix = e.Text.Substring(0, pos); String varname = e.Text.Substring(pos); possibleValues = settings.CompleteUserVariable(varname); } if (possibleValues.MoveNext()) { e.Output = variablePrefix + ((String) possibleValues.Current); } else { possibleValues.Reset(); } } } // the first word.. the command. else if (completeCommandString.Equals(e.Text)) { string text = e.Text.ToLower(); if (e.State == 0) { possibleValues = GetRegisteredCommandNames(text).GetEnumerator(); } while (HasNext(possibleValues)) { String nextKey = (String) possibleValues.Current; if (nextKey == null || nextKey.Length == 0) // don't complete the 'empty' thing. continue; if (text.Length < 1) { Command c = (Command) commandMap[nextKey]; if (!c.CommandCompletion) continue; if (c.RequiresContext && (application.ActiveContext == null || !application.ActiveContext.IsIsolated)) { continue; } } if (nextKey.StartsWith(text)) { e.Output = nextKey; break; } } } // .. otherwise get completion from the specific command. else { string text = e.Text.ToLower(); if (e.State == 0) { Command cmd = GetCommand(completeCommandString); if (cmd != null) possibleValues = cmd.Complete(this, completeCommandString, text); } while (HasNext(possibleValues)) { string key = (string) possibleValues.Current; if (key.ToLower().StartsWith(text)) { e.Output = key; break; } } } } catch(Exception ex) { Application.Error.WriteLine("An error occurred while TAB-completing: {0}", ex.Message); e.Error = true; possibleValues = null; throw; } }