From 1c7ebe241352a5892e93f1e207d94536ffeb2b96 Mon Sep 17 00:00:00 2001 From: Karlatemp Date: Thu, 19 Nov 2020 13:06:23 +0800 Subject: [PATCH] Suppress jline warning --- .../src/MiraiConsoleImplementationTerminal.kt | 66 ++++++++----------- 1 file changed, 28 insertions(+), 38 deletions(-) diff --git a/frontend/mirai-console-terminal/src/MiraiConsoleImplementationTerminal.kt b/frontend/mirai-console-terminal/src/MiraiConsoleImplementationTerminal.kt index 9cd5a3ead..581728676 100644 --- a/frontend/mirai-console-terminal/src/MiraiConsoleImplementationTerminal.kt +++ b/frontend/mirai-console-terminal/src/MiraiConsoleImplementationTerminal.kt @@ -103,48 +103,38 @@ val lineReader: LineReader by lazy { val terminal: Terminal = run { if (ConsoleTerminalSettings.noConsole) return@run NoConsole - val dumb = System.getProperty("java.class.path") - .contains("idea_rt.jar") || System.getProperty("mirai.idea") !== null || System.getenv("mirai.idea") !== null - - runCatching { - TerminalBuilder.builder() - .dumb(dumb) - .paused(true) - .build() - .let { terminal -> - if (terminal is AbstractWindowsTerminal) { - val pumpField = runCatching { - AbstractWindowsTerminal::class.java.getDeclaredField("pump").also { - it.isAccessible = true - } - }.onFailure { err -> - err.printStackTrace() - return@let terminal.also { it.resume() } - }.getOrThrow() - var response = terminal - terminal.setOnClose { - response = NoConsole + TerminalBuilder.builder() + .name("Mirai Console") + .system(true) + .jansi(true) + .dumb(true) + .paused(true) + .build() + .let { terminal -> + if (terminal is AbstractWindowsTerminal) { + val pumpField = runCatching { + AbstractWindowsTerminal::class.java.getDeclaredField("pump").also { + it.isAccessible = true } - terminal.resume() - val pumpThread = pumpField[terminal] as? Thread ?: return@let NoConsole - @Suppress("ControlFlowWithEmptyBody") - while (pumpThread.state == Thread.State.NEW); - Thread.sleep(1000) - terminal.setOnClose(null) - return@let response + }.onFailure { err -> + err.printStackTrace() + return@let terminal.also { it.resume() } + }.getOrThrow() + var response = terminal + terminal.setOnClose { + response = NoConsole } terminal.resume() - terminal + val pumpThread = pumpField[terminal] as? Thread ?: return@let NoConsole + @Suppress("ControlFlowWithEmptyBody") + while (pumpThread.state == Thread.State.NEW); + Thread.sleep(1000) + terminal.setOnClose(null) + return@let response } - }.recoverCatching { - TerminalBuilder.builder() - .jansi(true) - .build() - }.recoverCatching { - TerminalBuilder.builder() - .system(true) - .build() - }.getOrThrow() + terminal.resume() + terminal + } } private object ConsoleFrontEndDescImpl : MiraiConsoleFrontEndDescription {