Improve the console command completer
- Fix space after command getting removed when completing a subcommand together with the command prefix - Add support for completing without input (shows command list) - Sort command completion results - Fix console spamming command prefixes after closing the input stream
This commit is contained in:
parent
8e9feb21fa
commit
bb3596b31e
2 changed files with 15 additions and 13 deletions
|
@ -2,6 +2,7 @@ package net.minecraftforge.server.console;
|
|||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
@ -28,14 +29,9 @@ public final class ConsoleCommandCompleter implements Completer
|
|||
public int complete(String buffer, int cursor, List<CharSequence> candidates)
|
||||
{
|
||||
int len = buffer.length();
|
||||
buffer = buffer.trim();
|
||||
if (buffer.isEmpty())
|
||||
{
|
||||
return cursor;
|
||||
}
|
||||
|
||||
boolean prefix;
|
||||
if (buffer.charAt(0) != '/')
|
||||
if (buffer.isEmpty() || buffer.charAt(0) != '/')
|
||||
{
|
||||
buffer = '/' + buffer;
|
||||
prefix = false;
|
||||
|
@ -59,6 +55,7 @@ public final class ConsoleCommandCompleter implements Completer
|
|||
try
|
||||
{
|
||||
List<String> completions = tabComplete.get();
|
||||
Collections.sort(completions);
|
||||
if (prefix)
|
||||
{
|
||||
candidates.addAll(completions);
|
||||
|
@ -76,6 +73,10 @@ public final class ConsoleCommandCompleter implements Completer
|
|||
{
|
||||
return cursor - len;
|
||||
}
|
||||
else if (prefix)
|
||||
{
|
||||
return cursor - len + pos + 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
return cursor - len + pos;
|
||||
|
|
|
@ -34,14 +34,15 @@ public final class TerminalHandler
|
|||
try
|
||||
{
|
||||
line = reader.readLine("> ");
|
||||
|
||||
if (line != null)
|
||||
if (line == null)
|
||||
{
|
||||
line = line.trim();
|
||||
if (!line.isEmpty())
|
||||
{
|
||||
server.addPendingCommand(line, server);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
line = line.trim();
|
||||
if (!line.isEmpty())
|
||||
{
|
||||
server.addPendingCommand(line, server);
|
||||
}
|
||||
}
|
||||
catch (IOException e)
|
||||
|
|
Loading…
Reference in a new issue