From 6fc9adeb43f6f0c1b0b804d25e87b9b2141f4023 Mon Sep 17 00:00:00 2001 From: Him188 Date: Mon, 29 Jun 2020 16:17:50 +0800 Subject: [PATCH] Multiply terminal selection --- .../mamoe/mirai/console/pure/ConsoleUtils.kt | 17 ++++++++++++++--- .../console/pure/MiraiConsoleFrontEndPure.kt | 8 ++++---- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/frontend/mirai-console-pure/src/main/kotlin/net/mamoe/mirai/console/pure/ConsoleUtils.kt b/frontend/mirai-console-pure/src/main/kotlin/net/mamoe/mirai/console/pure/ConsoleUtils.kt index 3677a65f6..c9502a4f3 100644 --- a/frontend/mirai-console-pure/src/main/kotlin/net/mamoe/mirai/console/pure/ConsoleUtils.kt +++ b/frontend/mirai-console-pure/src/main/kotlin/net/mamoe/mirai/console/pure/ConsoleUtils.kt @@ -26,9 +26,20 @@ internal object ConsoleUtils { val dumb = System.getProperty("java.class.path") .contains("idea_rt.jar") || System.getProperty("mirai.idea") !== null || System.getenv("mirai.idea") !== null - terminal = TerminalBuilder.builder() - .jansi(true) - .build() + terminal = kotlin.runCatching { + TerminalBuilder.builder() + .dumb(dumb) + .build() + }.recoverCatching { + TerminalBuilder.builder() + .jansi(true) + .build() + }.recoverCatching { + TerminalBuilder.builder() + .system(true) + .build() + }.getOrThrow() + lineReader = LineReaderBuilder.builder() .terminal(terminal) .completer(NullCompleter()) diff --git a/frontend/mirai-console-pure/src/main/kotlin/net/mamoe/mirai/console/pure/MiraiConsoleFrontEndPure.kt b/frontend/mirai-console-pure/src/main/kotlin/net/mamoe/mirai/console/pure/MiraiConsoleFrontEndPure.kt index d3c790fea..5b797db6c 100644 --- a/frontend/mirai-console-pure/src/main/kotlin/net/mamoe/mirai/console/pure/MiraiConsoleFrontEndPure.kt +++ b/frontend/mirai-console-pure/src/main/kotlin/net/mamoe/mirai/console/pure/MiraiConsoleFrontEndPure.kt @@ -22,7 +22,8 @@ package net.mamoe.mirai.console.pure //import net.mamoe.mirai.console.command.CommandManager //import net.mamoe.mirai.console.utils.MiraiConsoleFrontEnd -import kotlinx.coroutines.suspendCancellableCoroutine +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.withContext import net.mamoe.mirai.Bot import net.mamoe.mirai.console.MiraiConsoleBuildConstants import net.mamoe.mirai.console.MiraiConsoleFrontEnd @@ -35,7 +36,6 @@ import org.fusesource.jansi.Ansi import java.text.SimpleDateFormat import java.util.* import java.util.concurrent.ConcurrentHashMap -import kotlin.coroutines.resume private val ANSI_RESET = Ansi().reset().toString() @@ -99,8 +99,8 @@ object MiraiConsoleFrontEndPure : MiraiConsoleFrontEnd { .toString() ) } - return suspendCancellableCoroutine { - it.resume(ConsoleUtils.lineReader.readLine("> ")) + return withContext(Dispatchers.IO) { + ConsoleUtils.lineReader.readLine("> ") } }