Further tries to bring colors to the terminal

Also added error support
#4
This commit is contained in:
Norbi Peti 2019-10-21 23:26:06 +02:00
parent 9dcfd600c7
commit 3857c85bea
No known key found for this signature in database
GPG key ID: DBA4C4549A927E56

View file

@ -1,5 +1,6 @@
package buttondevteam.serverrunner; package buttondevteam.serverrunner;
import jline.Terminal;
import jline.console.ConsoleReader; import jline.console.ConsoleReader;
import jline.console.CursorBuffer; import jline.console.CursorBuffer;
import org.yaml.snakeyaml.Yaml; import org.yaml.snakeyaml.Yaml;
@ -124,6 +125,29 @@ public class ServerRunner {
}; };
ot.setName("OutputThread"); ot.setName("OutputThread");
ot.start(); ot.start();
final Thread errt = new Thread() {
@Override
public void run() {
try {
BufferedReader serverinput = new BufferedReader(
new InputStreamReader(serverprocess.getErrorStream(), StandardCharsets.UTF_8));
String line;
while (true) {
if ((line = serverinput.readLine()) != null) {
writeToScreen(line);
} else if (stop)
break;
}
serverinput.close();
} catch (IOException e) {
e.printStackTrace();
}
ServerRunner.stop();
writeToScreen("Stopped " + Thread.currentThread().getName());
}
};
errt.setName("ErrorThread");
errt.start();
Thread.currentThread().setName("RestarterThread"); Thread.currentThread().setName("RestarterThread");
long starttime = syncStart(config.restartAt); long starttime = syncStart(config.restartAt);
writeToScreen("Restart scheduled in " + starttime / 3600000f); writeToScreen("Restart scheduled in " + starttime / 3600000f);
@ -170,8 +194,9 @@ public class ServerRunner {
} }
private static Process startServer(Config config, File serverJar) throws IOException { private static Process startServer(Config config, File serverJar) throws IOException {
ProcessBuilder pb = new ProcessBuilder(("java " + config.serverParams + " -jar " + serverJar.getPath()).split(" ")); ProcessBuilder pb = new ProcessBuilder("bash", "-i", "-c", "java " + config.serverParams + " -jar " + serverJar.getPath());
pb.environment().put("TERM", "xterm"); pb.environment().put("TERM", "xterm");
Terminal t;
return pb.start(); return pb.start();
/*return Runtime.getRuntime().exec(, /*return Runtime.getRuntime().exec(,
new String[] { "TERM=xterm" }); //Need to use split() because of the supplied params*/ new String[] { "TERM=xterm" }); //Need to use split() because of the supplied params*/