feat: Switch to JLine. #72

Merged
Norbiros merged 2 commits from feat/use-jline into main 2023-08-14 20:48:08 +00:00
2 changed files with 24 additions and 17 deletions

No files matched your search

+1
View File
@@ -21,6 +21,7 @@ dependencies {
implementation 'com.diogonunes:JColor:5.2.0' implementation 'com.diogonunes:JColor:5.2.0'
implementation 'dnsjava:dnsjava:3.4.3' implementation 'dnsjava:dnsjava:3.4.3'
implementation 'org.slf4j:slf4j-nop:1.7.32' implementation 'org.slf4j:slf4j-nop:1.7.32'
implementation 'org.jline:jline:3.22.0'
} }
jar { jar {
+23 -17
View File
@@ -7,6 +7,11 @@ import com.github.steveice10.mc.auth.util.HTTP;
import com.github.steveice10.mc.protocol.data.status.ServerStatusInfo; import com.github.steveice10.mc.protocol.data.status.ServerStatusInfo;
import com.github.steveice10.packetlib.ProxyInfo; import com.github.steveice10.packetlib.ProxyInfo;
import org.apache.commons.cli.*; import org.apache.commons.cli.*;
import org.jline.reader.LineReader;
import org.jline.reader.LineReaderBuilder;
import org.jline.reader.UserInterruptException;
import org.jline.terminal.Terminal;
import org.jline.terminal.TerminalBuilder;
import org.xbill.DNS.Lookup; import org.xbill.DNS.Lookup;
import org.xbill.DNS.Record; import org.xbill.DNS.Record;
import org.xbill.DNS.SRVRecord; import org.xbill.DNS.SRVRecord;
@@ -390,12 +395,22 @@ public class Main {
}, 1000L, 500L); }, 1000L, 500L);
} }
Terminal terminal = TerminalBuilder.builder().build();
LineReader lineReader = LineReaderBuilder.builder()
.terminal(terminal)
.parser(new org.jline.reader.impl.DefaultParser())
.build();
Scanner scanner = new Scanner(System.in);
prompt = "ALL"; prompt = "ALL";
while (scanner.hasNextLine()) {
String line = scanner.nextLine();
while (true) {
String line;
try {
line = lineReader.readLine();
} catch (UserInterruptException e) {
System.exit(0);
break;
}
if (line.isEmpty()) { if (line.isEmpty()) {
System.out.print(getPrompt() + "> "); System.out.print(getPrompt() + "> ");
continue; continue;
@@ -456,16 +471,12 @@ public class Main {
// List command // List command
else if (commandName.equalsIgnoreCase("list") || commandName.equalsIgnoreCase("ls")) else if (commandName.equalsIgnoreCase("list") || commandName.equalsIgnoreCase("ls")) {
{
Log.info("There are " + bots.size() + " bots connected:"); Log.info("There are " + bots.size() + " bots connected:");
for (Bot bot : bots) { for (Bot bot : bots) {
Log.info(bot.getNickname(), bot.hasMainListener() ? "[MainListener]" : ""); Log.info(bot.getNickname(), bot.hasMainListener() ? "[MainListener]" : "");
} }
} } else if (commandName.equalsIgnoreCase("leave") || commandName.equalsIgnoreCase("exit")) {
else if (commandName.equalsIgnoreCase("leave") || commandName.equalsIgnoreCase("exit"))
{
int limit = -1; int limit = -1;
if (split.length >= 2) { if (split.length >= 2) {
try { try {
@@ -496,17 +507,12 @@ public class Main {
bot.disconnect(); bot.disconnect();
} }
} }
} } else {
else {
Log.warn("Invalid command"); Log.warn("Invalid command");
} }
} } else if (controlledBots.size() > 0) {
else if (controlledBots.size() > 0) {
controlledBots.forEach(bot -> bot.sendChat(line)); controlledBots.forEach(bot -> bot.sendChat(line));
} } else {
else {
bots.forEach(bot -> bot.sendChat(line)); bots.forEach(bot -> bot.sendChat(line));
} }