diff --git a/Launcher/runtime/dialog/dialog.js b/Launcher/runtime/dialog/dialog.js index f3e36512..b6c6dbcb 100644 --- a/Launcher/runtime/dialog/dialog.js +++ b/Launcher/runtime/dialog/dialog.js @@ -122,6 +122,16 @@ function initConsoleScene() { pane.lookup("#close").setOnAction(function(){ consoleStage.hide(); }); + var text = consoleMenu.lookup("#textField"); + var output = consoleMenu.lookup("#output"); + var appendFunction = function(line) javafx.application.Platform.runLater(function() output.appendText(line)); + consoleMenu.lookup("#send").setOnAction(function(){ + execCommand(text.getText()); + text.setText(""); + }); + FunctionalBridge.addPlainOutput(function(string) { + appendFunction(string+"\n"); + }) pane.lookup("#hide").setOnAction(function(event) { consoleStage.setIconified(true) }); var pane = consoleMenu.lookup("#consolePane"); @@ -456,3 +466,4 @@ launcher.loadScript("dialog/overlay/update/update.js"); /* ======== Overlays scripts ======== */ launcher.loadScript("dialog/scenes/options/options.js"); +launcher.loadScript("dialog/scenes/console/console.js"); diff --git a/Launcher/runtime/dialog/scenes/console/console.fxml b/Launcher/runtime/dialog/scenes/console/console.fxml index 9b139631..face3105 100644 --- a/Launcher/runtime/dialog/scenes/console/console.fxml +++ b/Launcher/runtime/dialog/scenes/console/console.fxml @@ -32,7 +32,7 @@ - + @@ -40,7 +40,7 @@ - + diff --git a/Launcher/runtime/dialog/scenes/console/console.js b/Launcher/runtime/dialog/scenes/console/console.js new file mode 100644 index 00000000..e4451fb8 --- /dev/null +++ b/Launcher/runtime/dialog/scenes/console/console.js @@ -0,0 +1,3 @@ +function execCommand(cmd) { + FunctionalBridge.evalCommand(cmd); +} \ No newline at end of file diff --git a/Launcher/src/main/java/ru/gravit/launcher/LauncherEngine.java b/Launcher/src/main/java/ru/gravit/launcher/LauncherEngine.java index fbe7f53a..fec9b5b3 100644 --- a/Launcher/src/main/java/ru/gravit/launcher/LauncherEngine.java +++ b/Launcher/src/main/java/ru/gravit/launcher/LauncherEngine.java @@ -7,6 +7,7 @@ import ru.gravit.launcher.gui.JSRuntimeProvider; import ru.gravit.launcher.gui.RuntimeProvider; import ru.gravit.launcher.managers.ClientGsonManager; +import ru.gravit.launcher.managers.ConsoleManager; import ru.gravit.launcher.request.Request; import ru.gravit.launcher.request.websockets.ClientWebSocketService; import ru.gravit.launcher.request.websockets.StandartClientWebSocketService; @@ -29,6 +30,7 @@ public static void main(String... args) throws Throwable { LogHelper.printLicense("Launcher"); // Start Launcher initGson(); + ConsoleManager.initConsole(); LogHelper.setStacktraceEnabled(true); long startTime = System.currentTimeMillis(); try { diff --git a/Launcher/src/main/java/ru/gravit/launcher/client/FunctionalBridge.java b/Launcher/src/main/java/ru/gravit/launcher/client/FunctionalBridge.java index e22bfbfd..571dab73 100644 --- a/Launcher/src/main/java/ru/gravit/launcher/client/FunctionalBridge.java +++ b/Launcher/src/main/java/ru/gravit/launcher/client/FunctionalBridge.java @@ -7,11 +7,14 @@ import ru.gravit.launcher.hasher.FileNameMatcher; import ru.gravit.launcher.hasher.HashedDir; import ru.gravit.launcher.hwid.OshiHWIDProvider; +import ru.gravit.launcher.managers.ConsoleManager; import ru.gravit.launcher.managers.HasherManager; import ru.gravit.launcher.managers.HasherStore; import ru.gravit.launcher.request.Request; import ru.gravit.launcher.request.websockets.RequestInterface; import ru.gravit.launcher.serialize.signed.SignedObjectHolder; +import ru.gravit.utils.helper.CommonHelper; +import ru.gravit.utils.helper.LogHelper; import java.nio.file.Path; import java.util.concurrent.Executors; @@ -104,4 +107,14 @@ public static void setAuthParams(AuthRequestEvent event) { public interface HashedDirRunnable { SignedObjectHolder run() throws Exception; } + @LauncherAPI + public static void evalCommand(String cmd) + { + ConsoleManager.handler.eval(cmd, false); + } + @LauncherAPI + public static void addPlainOutput(LogHelper.Output output) + { + LogHelper.addOutput(output, LogHelper.OutputTypes.PLAIN); + } } diff --git a/Launcher/src/main/java/ru/gravit/launcher/managers/ConsoleManager.java b/Launcher/src/main/java/ru/gravit/launcher/managers/ConsoleManager.java new file mode 100644 index 00000000..2e9c3e58 --- /dev/null +++ b/Launcher/src/main/java/ru/gravit/launcher/managers/ConsoleManager.java @@ -0,0 +1,37 @@ +package ru.gravit.launcher.managers; + +import ru.gravit.utils.command.CommandHandler; +import ru.gravit.utils.command.JLineCommandHandler; +import ru.gravit.utils.command.StdCommandHandler; +import ru.gravit.utils.command.basic.HelpCommand; +import ru.gravit.utils.helper.CommonHelper; +import ru.gravit.utils.helper.LogHelper; + +import java.io.IOException; + +public class ConsoleManager { + public static CommandHandler handler; + public static Thread thread; + public static void initConsole() throws IOException + { + CommandHandler localCommandHandler; + try { + Class.forName("jline.Terminal"); + + // JLine2 available + localCommandHandler = new JLineCommandHandler(); + LogHelper.info("JLine2 terminal enabled"); + } catch (ClassNotFoundException ignored) { + localCommandHandler = new StdCommandHandler(true); + LogHelper.warning("JLine2 isn't in classpath, using std"); + } + handler = localCommandHandler; + registerCommands(); + thread = CommonHelper.newThread("Launcher Console", true, handler); + thread.start(); + } + public static void registerCommands() + { + handler.registerCommand("help", new HelpCommand(handler)); + } +}