mirror of
https://github.com/GravitLauncher/Launcher
synced 2025-01-22 15:24:23 +03:00
[FEATURE] Автокомплит
This commit is contained in:
parent
179733a987
commit
31ac1895af
2 changed files with 35 additions and 3 deletions
|
@ -7,6 +7,7 @@
|
|||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public abstract class CommandHandler implements Runnable {
|
||||
private final List<Category> categories = new ArrayList<>();
|
||||
|
@ -130,6 +131,21 @@ public void run() {
|
|||
LogHelper.error(e);
|
||||
}
|
||||
}
|
||||
@FunctionalInterface
|
||||
public interface CommandWalk
|
||||
{
|
||||
void walk(Category category, String name, Command command);
|
||||
}
|
||||
public void walk(CommandWalk callback)
|
||||
{
|
||||
for(CommandHandler.Category category : getCategories())
|
||||
{
|
||||
for (Map.Entry<String, Command> entry : category.category.commandsMap().entrySet())
|
||||
callback.walk(category, entry.getKey(), entry.getValue());
|
||||
}
|
||||
for (Map.Entry<String, Command> entry : getBaseCategory().commandsMap().entrySet())
|
||||
callback.walk(null, entry.getKey(), entry.getValue());
|
||||
}
|
||||
|
||||
public CommandCategory getBaseCategory() {
|
||||
return baseCategory;
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package ru.gravit.utils.command;
|
||||
|
||||
import org.jline.reader.LineReader;
|
||||
import org.jline.reader.LineReaderBuilder;
|
||||
import org.jline.reader.*;
|
||||
import org.jline.terminal.Terminal;
|
||||
import org.jline.terminal.TerminalBuilder;
|
||||
import org.jline.utils.InfoCmp;
|
||||
|
@ -9,6 +8,7 @@
|
|||
import ru.gravit.utils.helper.LogHelper.Output;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
public class JLineCommandHandler extends CommandHandler {
|
||||
/*private final class JLineOutput implements Output {
|
||||
|
@ -26,14 +26,30 @@ public void println(String message) {
|
|||
|
||||
private final Terminal terminal;
|
||||
private final TerminalBuilder terminalBuilder;
|
||||
private final Completer completer;
|
||||
private final LineReader reader;
|
||||
public class JLineConsoleCompleter implements Completer {
|
||||
@Override
|
||||
public void complete(LineReader reader, ParsedLine line, List<Candidate> candidates) {
|
||||
String completeWord = line.word();
|
||||
if(line.wordIndex() != 0) return;
|
||||
walk((category, name, command) -> {
|
||||
if(name.startsWith(completeWord))
|
||||
{
|
||||
candidates.add(new Candidate(name));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public JLineCommandHandler() throws IOException {
|
||||
super();
|
||||
terminalBuilder = TerminalBuilder.builder();
|
||||
terminal = terminalBuilder.build();
|
||||
completer = new JLineConsoleCompleter();
|
||||
reader = LineReaderBuilder.builder()
|
||||
.terminal(terminal)
|
||||
.completer(completer)
|
||||
.build();
|
||||
|
||||
// Set reader
|
||||
|
@ -47,7 +63,7 @@ public JLineCommandHandler() throws IOException {
|
|||
|
||||
@Override
|
||||
public void bell() throws IOException {
|
||||
|
||||
terminal.puts(InfoCmp.Capability.bell);
|
||||
//reader.beep();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue