Commit 91e9a5b0 authored by jiahua.liu's avatar jiahua.liu

terminal update

parent 3eab26a5
......@@ -37,8 +37,7 @@ object MiraiConsole {
val pluginManager: PluginManager
get() = PluginManager
var logger: MiraiConsoleLogger =
UIPushLogger()
var logger = UIPushLogger(0)
var path: String = System.getProperty("user.dir")
......@@ -255,11 +254,11 @@ object MiraiConsole {
}
}
class UIPushLogger(override val identity: String?, override var follower: MiraiLogger?) : MiraiLogger {
override fun invoke(any: Any?) {
class UIPushLogger(val identity: Long) {
operator fun invoke(any: Any? = null) {
MiraiConsoleUI.start()
if (any != null) {
MiraiConsoleUI.pushLog(0, "[Mirai$version $build]: $any")
MiraiConsoleUI.pushLog(identity, "[Mirai$version $build]: $any")
}
}
}
......
......@@ -29,9 +29,9 @@ object MiraiConsoleUI {
log[uin] = LimitLinkedQueue()
}
fun pushLog(uin: Long, str: String) {
log[uin]!!.push(str)
}
lateinit var terminal: Terminal
lateinit var textGraphics: TextGraphics
var hasStart = false
fun start() {
......@@ -40,25 +40,64 @@ object MiraiConsoleUI {
}
hasStart = true
val defaultTerminalFactory = DefaultTerminalFactory()
var terminal: Terminal? = null
try {
terminal = defaultTerminalFactory.createTerminal()
terminal.enterPrivateMode()
terminal.clearScreen()
terminal.setCursorVisible(false)
} catch (e: Exception) {
try {
terminal = SwingTerminalFrame("Mirai Console")
terminal.enterPrivateMode()
terminal.clearScreen()
terminal.setCursorVisible(false)
}
if (terminal == null) {
} catch (e: Exception) {
error("can not create terminal")
}
}
textGraphics = terminal.newTextGraphics()
val textGraphics: TextGraphics = terminal.newTextGraphics()
terminal.addResizeListener(TerminalResizeListener { terminal1: Terminal, newSize: TerminalSize ->
terminal.clearScreen()
inited = false
update()
redrawCommand()
})
update()
val charList = listOf(',', '.', '/', '@', '#', '$', '%', '^', '&', '*', '(', ')', '_', '=', '+', '!', ' ')
thread {
while (true) {
var keyStroke: KeyStroke = terminal.readInput()
when (keyStroke.keyType) {
KeyType.ArrowLeft -> {
currentScreenId = getLeftScreenId()
update()
}
KeyType.ArrowRight -> {
currentScreenId = getRightScreenId()
update()
}
KeyType.Enter -> {
emptyCommand()
}
else -> {
if (keyStroke.character != null) {
if (keyStroke.character.toInt() == 8) {
deleteCommandChar()
}
if (keyStroke.character.isLetterOrDigit() || charList.contains(keyStroke.character)) {
addCommandChar(keyStroke.character)
}
}
}
}
}
}
}
try {
fun getLeftScreenId(): Int {
var newId = currentScreenId - 1
if (newId < 0) {
......@@ -188,9 +227,15 @@ object MiraiConsoleUI {
}
}
if (terminal is SwingTerminalFrame) {
textGraphics.putString(3, 9, "AAAAAAAAAAAAAAAAAAAAAAa", SGR.ITALIC)
terminal.flush()
}
fun pushLog(uin: Long, str: String) {
log[uin]!!.push(str)
if (uin == screens[currentScreenId]) {
drawLogs(log[screens[currentScreenId]]!!)
}
}
......@@ -257,58 +302,12 @@ object MiraiConsoleUI {
}
}
terminal.flush()
}
terminal.addResizeListener(TerminalResizeListener { terminal1: Terminal, newSize: TerminalSize ->
terminal.clearScreen()
inited = false
update()
redrawCommand()
})
update()
val charList = listOf(',', '.', '/', '@', '#', '$', '%', '^', '&', '*', '(', ')', '_', '=', '+', '!', ' ')
thread {
while (true) {
var keyStroke: KeyStroke = terminal.readInput()
when (keyStroke.keyType) {
KeyType.ArrowLeft -> {
currentScreenId = getLeftScreenId()
update()
}
KeyType.ArrowRight -> {
currentScreenId = getRightScreenId()
update()
}
KeyType.Enter -> {
emptyCommand()
}
else -> {
if (keyStroke.character != null) {
if (keyStroke.character.toInt() == 8) {
deleteCommandChar()
}
if (keyStroke.character.isLetterOrDigit() || charList.contains(keyStroke.character)) {
addCommandChar(keyStroke.character)
}
}
}
}
}
}
} catch (e: Exception) {
e.printStackTrace()
}
}
}
class LimitLinkedQueue<T>(
val limit: Int = 50
) : LinkedList<T>() {
) : LinkedList<T>(), List<T> {
override fun push(e: T) {
if (size >= limit) {
pollLast()
......
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