From 9828bbf69417c139472425b87297c74445e2bd1e Mon Sep 17 00:00:00 2001 From: "jiahua.liu" Date: Mon, 17 Feb 2020 17:00:20 +0800 Subject: [PATCH] mirai console shutdown logic --- .../net/mamoe/mirai/console/MiraiConsoleTerminalLoader.kt | 1 + .../net/mamoe/mirai/console/MiraiConsoleTerminalUI.kt | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/mirai-console-terminal/src/main/kotlin/net/mamoe/mirai/console/MiraiConsoleTerminalLoader.kt b/mirai-console-terminal/src/main/kotlin/net/mamoe/mirai/console/MiraiConsoleTerminalLoader.kt index d302d7db7..5e97c668e 100644 --- a/mirai-console-terminal/src/main/kotlin/net/mamoe/mirai/console/MiraiConsoleTerminalLoader.kt +++ b/mirai-console-terminal/src/main/kotlin/net/mamoe/mirai/console/MiraiConsoleTerminalLoader.kt @@ -23,6 +23,7 @@ class MiraiConsoleTerminalLoader { } Runtime.getRuntime().addShutdownHook(thread(start = false) { MiraiConsole.stop() + MiraiConsoleTerminalUI.exit() }) } } diff --git a/mirai-console-terminal/src/main/kotlin/net/mamoe/mirai/console/MiraiConsoleTerminalUI.kt b/mirai-console-terminal/src/main/kotlin/net/mamoe/mirai/console/MiraiConsoleTerminalUI.kt index 5fe7a4dd4..834326ee2 100644 --- a/mirai-console-terminal/src/main/kotlin/net/mamoe/mirai/console/MiraiConsoleTerminalUI.kt +++ b/mirai-console-terminal/src/main/kotlin/net/mamoe/mirai/console/MiraiConsoleTerminalUI.kt @@ -353,7 +353,7 @@ object MiraiConsoleTerminalUI : MiraiConsoleUI { emptyCommand() } KeyType.Escape -> { - exitProcess(0) + exit() } else -> { if (keyStroke.character != null) { @@ -649,6 +649,12 @@ object MiraiConsoleTerminalUI : MiraiConsoleUI { } redrawLogs(log[screens[currentScreenId]]!!) } + + fun exit() { + terminal.exitPrivateMode() + terminal.close() + exitProcess(0) + } }