mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-01 13:58:24 +08:00
terminal console closable
This commit is contained in:
parent
7357c65e72
commit
924fa65f6a
@ -12,7 +12,7 @@ class MiraiConsoleTerminalLoader {
|
||||
).toLowerCase().contains("windows")
|
||||
) {
|
||||
println("[MiraiConsoleTerminalLoader]: 将以Pure[兼容模式]启动Console")
|
||||
MiraiConsole.start(MiraiConsoleUIPure)
|
||||
MiraiConsole.start(MiraiConsoleUIPure())
|
||||
} else {
|
||||
MiraiConsoleTerminalUI.start()
|
||||
thread {
|
||||
|
@ -643,7 +643,7 @@ object MiraiConsoleTerminalUI : MiraiConsoleUI {
|
||||
terminal.close()
|
||||
exitProcess(0)
|
||||
} catch (ignored: Exception) {
|
||||
exitProcess(0)
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -7,7 +7,6 @@ plugins {
|
||||
|
||||
apply(plugin = "com.github.johnrengelman.shadow")
|
||||
|
||||
|
||||
val kotlinVersion: String by rootProject.ext
|
||||
val atomicFuVersion: String by rootProject.ext
|
||||
val coroutinesVersion: String by rootProject.ext
|
||||
@ -25,7 +24,7 @@ fun ktor(id: String, version: String) = "io.ktor:ktor-$id:$version"
|
||||
|
||||
tasks.withType<com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar>() {
|
||||
manifest {
|
||||
attributes["Main-Class"] = "net.mamoe.mirai.console.MiraiConsoleUIPureLoader"
|
||||
attributes["Main-Class"] = "net.mamoe.mirai.console.MiraiConsolePureLoader"
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -83,8 +83,12 @@ object MiraiConsole {
|
||||
fun stop() {
|
||||
PluginManager.disableAllPlugins()
|
||||
allDown = true
|
||||
bots.forEach {
|
||||
it.get()?.close()
|
||||
try {
|
||||
bots.forEach {
|
||||
it.get()?.close()
|
||||
}
|
||||
} catch (ignored: Exception) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,11 +1,29 @@
|
||||
package net.mamoe.mirai.console
|
||||
|
||||
import kotlinx.coroutines.delay
|
||||
import net.mamoe.mirai.Bot
|
||||
import net.mamoe.mirai.utils.DefaultLoginSolver
|
||||
import net.mamoe.mirai.utils.LoginSolver
|
||||
import kotlin.concurrent.thread
|
||||
|
||||
object MiraiConsoleUIPure : MiraiConsoleUI {
|
||||
class MiraiConsoleUIPure() : MiraiConsoleUI {
|
||||
var requesting = false
|
||||
var requestStr = ""
|
||||
|
||||
init {
|
||||
thread {
|
||||
while (true) {
|
||||
val input = readLine() ?: ""
|
||||
if (requesting) {
|
||||
requestStr = input
|
||||
requesting = false
|
||||
} else {
|
||||
MiraiConsole.CommandListener.commandChannel.offer(input)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun pushLog(identity: Long, message: String) {
|
||||
println(message)
|
||||
}
|
||||
@ -23,7 +41,13 @@ object MiraiConsoleUIPure : MiraiConsoleUI {
|
||||
}
|
||||
|
||||
override suspend fun requestInput(question: String): String {
|
||||
return readLine() ?: ""
|
||||
requesting = true
|
||||
while (true) {
|
||||
delay(50)
|
||||
if (!requesting) {
|
||||
return requestStr
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun pushBotAdminStatus(identity: Long, admins: List<Long>) {
|
||||
@ -41,7 +65,7 @@ class MiraiConsolePureLoader {
|
||||
companion object {
|
||||
@JvmStatic
|
||||
fun main(args: Array<String>) {
|
||||
MiraiConsole.start(MiraiConsoleUIPure)
|
||||
MiraiConsole.start(MiraiConsoleUIPure())
|
||||
Runtime.getRuntime().addShutdownHook(thread(start = false) {
|
||||
MiraiConsole.stop()
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user