Commit 2ed0411c authored by jiahua.liu's avatar jiahua.liu

ConsoleUI warning

parent 0e4c9916
...@@ -43,5 +43,6 @@ dependencies { ...@@ -43,5 +43,6 @@ dependencies {
api(group = "org.yaml", name = "snakeyaml", version = "1.25") api(group = "org.yaml", name = "snakeyaml", version = "1.25")
api(group = "com.moandjiezana.toml", name = "toml4j", version = "0.7.2") api(group = "com.moandjiezana.toml", name = "toml4j", version = "0.7.2")
api(group = "com.googlecode.lanterna", name = "lanterna", version = "3.0.2") api(group = "com.googlecode.lanterna", name = "lanterna", version = "3.0.2")
api("org.bouncycastle:bcprov-jdk15on:1.64")
// classpath is not set correctly by IDE // classpath is not set correctly by IDE
} }
\ No newline at end of file
...@@ -10,19 +10,22 @@ package net.mamoe.mirai ...@@ -10,19 +10,22 @@ package net.mamoe.mirai
*/ */
import kotlinx.coroutines.runBlocking import kotlinx.coroutines.runBlocking
import net.mamoe.mirai.api.http.MiraiHttpAPIServer
import net.mamoe.mirai.api.http.generateSessionKey
import net.mamoe.mirai.contact.sendMessage
import net.mamoe.mirai.plugins.PluginManager import net.mamoe.mirai.plugins.PluginManager
import net.mamoe.mirai.plugins.loadAsConfig import net.mamoe.mirai.plugins.loadAsConfig
import net.mamoe.mirai.plugins.withDefaultWrite import net.mamoe.mirai.plugins.withDefaultWrite
import net.mamoe.mirai.plugins.withDefaultWriteSave import net.mamoe.mirai.plugins.withDefaultWriteSave
import net.mamoe.mirai.api.http.MiraiHttpAPIServer
import net.mamoe.mirai.api.http.generateSessionKey
import net.mamoe.mirai.contact.sendMessage
import net.mamoe.mirai.utils.MiraiLogger
import net.mamoe.mirai.utils.SimpleLogger import net.mamoe.mirai.utils.SimpleLogger
import org.bouncycastle.jce.provider.BouncyCastleProvider
import java.io.File import java.io.File
import java.io.PrintStream import java.security.Security
import java.util.*
import java.util.concurrent.LinkedBlockingQueue
import kotlin.concurrent.thread import kotlin.concurrent.thread
object MiraiConsole { object MiraiConsole {
val bots val bots
get() = Bot.instances get() = Bot.instances
...@@ -48,7 +51,6 @@ object MiraiConsole { ...@@ -48,7 +51,6 @@ object MiraiConsole {
val build = "Beta" val build = "Beta"
fun start() { fun start() {
MiraiConsoleUI.start()
logger("Mirai-console [v$version $build | core version v$coreVersion] is still in testing stage, majority feature is available") logger("Mirai-console [v$version $build | core version v$coreVersion] is still in testing stage, majority feature is available")
logger("Mirai-console now running under " + System.getProperty("user.dir")) logger("Mirai-console now running under " + System.getProperty("user.dir"))
logger("Get news in github: https://github.com/mamoe/mirai") logger("Get news in github: https://github.com/mamoe/mirai")
...@@ -65,7 +67,6 @@ object MiraiConsole { ...@@ -65,7 +67,6 @@ object MiraiConsole {
logger("Mirai-console 启动完成") logger("Mirai-console 启动完成")
logger("\"/login qqnumber qqpassword \" to login a bot") logger("\"/login qqnumber qqpassword \" to login a bot")
logger("\"/login qq号 qq密码 \" 来登陆一个BOT") logger("\"/login qq号 qq密码 \" 来登陆一个BOT")
} }
fun stop() { fun stop() {
...@@ -108,14 +109,15 @@ object MiraiConsole { ...@@ -108,14 +109,15 @@ object MiraiConsole {
} }
val qqNumber = it[0].toLong() val qqNumber = it[0].toLong()
val qqPassword = it[1] val qqPassword = it[1]
logger("login...") logger("[Bot Login]", 0, "login...")
try { try {
runBlocking { runBlocking {
Bot(qqNumber, qqPassword).alsoLogin() Bot(qqNumber, qqPassword).alsoLogin()
println("$qqNumber login successes") logger("[Bot Login]", 0, "$qqNumber login successes")
} }
} catch (e: Exception) { } catch (e: Exception) {
println("$qqNumber login failed") logger("[Bot Login]", 0, "$qqNumber login failed -> " + e.message)
e.printStackTrace()
} }
true true
} }
...@@ -234,14 +236,15 @@ object MiraiConsole { ...@@ -234,14 +236,15 @@ object MiraiConsole {
} }
object CommandListener { object CommandListener {
val commandChannel: Queue<String> = LinkedBlockingQueue<String>()
fun start() { fun start() {
thread { thread {
//processNextCommandLine() processNextCommandLine()
} }
} }
tailrec fun processNextCommandLine() { tailrec fun processNextCommandLine() {
var fullCommand = readLine() var fullCommand = commandChannel.poll()
if (fullCommand != null) { if (fullCommand != null) {
if (!fullCommand.startsWith("/")) { if (!fullCommand.startsWith("/")) {
fullCommand = "/$fullCommand" fullCommand = "/$fullCommand"
...@@ -283,11 +286,14 @@ class MiraiConsoleLoader { ...@@ -283,11 +286,14 @@ class MiraiConsoleLoader {
companion object { companion object {
@JvmStatic @JvmStatic
fun main(args: Array<String>) { fun main(args: Array<String>) {
Security.removeProvider("BC")
Security.addProvider(BouncyCastleProvider())
//Security.addProvider(BouncyCastle)
MiraiConsoleUI.start()
MiraiConsole.start() MiraiConsole.start()
Runtime.getRuntime().addShutdownHook(thread(start = false) { Runtime.getRuntime().addShutdownHook(thread(start = false) {
MiraiConsole.stop() MiraiConsole.stop()
}) })
} }
} }
} }
......
...@@ -168,6 +168,7 @@ object MiraiConsoleUI { ...@@ -168,6 +168,7 @@ object MiraiConsoleUI {
update() update()
} }
KeyType.Enter -> { KeyType.Enter -> {
MiraiConsole.CommandListener.commandChannel.offer(commandBuilder.toString())
emptyCommand() emptyCommand()
} }
else -> { else -> {
...@@ -290,8 +291,6 @@ object MiraiConsoleUI { ...@@ -290,8 +291,6 @@ object MiraiConsoleUI {
if (currentHeight + heightNeed > maxHeight) { if (currentHeight + heightNeed > maxHeight) {
cleanPage() cleanPage()
} }
textGraphics.foregroundColor = TextColor.ANSI.GREEN
textGraphics.backgroundColor = TextColor.ANSI.DEFAULT
val width = terminal.terminalSize.columns - 7 val width = terminal.terminalSize.columns - 7
var x = string var x = string
while (true) { while (true) {
...@@ -306,6 +305,8 @@ object MiraiConsoleUI { ...@@ -306,6 +305,8 @@ object MiraiConsoleUI {
} }
} }
try { try {
textGraphics.foregroundColor = TextColor.ANSI.GREEN
textGraphics.backgroundColor = TextColor.ANSI.DEFAULT
textGraphics.putString(3, currentHeight, toWrite, SGR.ITALIC) textGraphics.putString(3, currentHeight, toWrite, SGR.ITALIC)
} catch (ignored: Exception) { } catch (ignored: Exception) {
// //
...@@ -401,11 +402,23 @@ object MiraiConsoleUI { ...@@ -401,11 +402,23 @@ object MiraiConsoleUI {
} }
var lastEmpty: Job? = null
private fun emptyCommand() { private fun emptyCommand() {
commandBuilder = StringBuilder() commandBuilder = StringBuilder()
redrawCommand()
if (terminal is SwingTerminal) { if (terminal is SwingTerminal) {
redrawCommand()
terminal.flush() terminal.flush()
} else {
lastEmpty = GlobalScope.launch {
delay(100)
if (lastEmpty == coroutineContext[Job]) {
terminal.clearScreen()
//inited = false
update()
redrawCommand()
redrawLogs(log[screens[currentScreenId]]!!)
}
}
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment