mirror of
https://github.com/mamoe/mirai.git
synced 2025-03-22 05:10:09 +08:00
console frame complete
This commit is contained in:
parent
e27c9bd459
commit
4e046c71f8
@ -48,16 +48,10 @@ object MiraiConsole {
|
|||||||
|
|
||||||
fun start() {
|
fun 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 v$version $build | 核心版本 v${coreVersion}还处于测试阶段, 大部分功能可用")
|
|
||||||
logger()
|
|
||||||
logger("Mirai-console now running under " + System.getProperty("user.dir"))
|
logger("Mirai-console now running under " + System.getProperty("user.dir"))
|
||||||
logger("Mirai-console 正在 " + System.getProperty("user.dir") + "下运行")
|
|
||||||
logger()
|
|
||||||
logger("Get news in github: https://github.com/mamoe/mirai")
|
logger("Get news in github: https://github.com/mamoe/mirai")
|
||||||
logger("在Github中获取项目最新进展: https://github.com/mamoe/mirai")
|
|
||||||
logger("Mirai为开源项目,请自觉遵守开源项目协议")
|
logger("Mirai为开源项目,请自觉遵守开源项目协议")
|
||||||
logger("Powered by Mamoe Technologies and contributors")
|
logger("Powered by Mamoe Technologies and contributors")
|
||||||
logger()
|
|
||||||
|
|
||||||
runBlocking {
|
runBlocking {
|
||||||
DefaultCommands()
|
DefaultCommands()
|
||||||
|
@ -11,6 +11,8 @@ import com.googlecode.lanterna.terminal.Terminal
|
|||||||
import com.googlecode.lanterna.terminal.TerminalResizeListener
|
import com.googlecode.lanterna.terminal.TerminalResizeListener
|
||||||
import com.googlecode.lanterna.terminal.swing.SwingTerminal
|
import com.googlecode.lanterna.terminal.swing.SwingTerminal
|
||||||
import com.googlecode.lanterna.terminal.swing.SwingTerminalFrame
|
import com.googlecode.lanterna.terminal.swing.SwingTerminalFrame
|
||||||
|
import kotlinx.coroutines.*
|
||||||
|
import net.mamoe.mirai.MiraiConsoleUI.LoggerDrawer.cleanPage
|
||||||
import net.mamoe.mirai.MiraiConsoleUI.LoggerDrawer.drawLog
|
import net.mamoe.mirai.MiraiConsoleUI.LoggerDrawer.drawLog
|
||||||
import net.mamoe.mirai.MiraiConsoleUI.LoggerDrawer.redrawLogs
|
import net.mamoe.mirai.MiraiConsoleUI.LoggerDrawer.redrawLogs
|
||||||
import net.mamoe.mirai.utils.currentTimeSeconds
|
import net.mamoe.mirai.utils.currentTimeSeconds
|
||||||
@ -24,10 +26,13 @@ import kotlin.math.ceil
|
|||||||
|
|
||||||
object MiraiConsoleUI {
|
object MiraiConsoleUI {
|
||||||
|
|
||||||
val log = mutableMapOf<Long, LimitLinkedQueue<String>>().also { it[0L] = LimitLinkedQueue(50) }
|
val log = mutableMapOf<Long, LimitLinkedQueue<String>>().also {
|
||||||
|
it[0L] = LimitLinkedQueue(50)
|
||||||
|
it[2821869985L] = LimitLinkedQueue(50)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private val screens = mutableListOf(0L)
|
private val screens = mutableListOf(0L, 2821869985L)
|
||||||
private var currentScreenId = 0
|
private var currentScreenId = 0
|
||||||
|
|
||||||
fun addBotScreen(uin: Long) {
|
fun addBotScreen(uin: Long) {
|
||||||
@ -68,12 +73,46 @@ object MiraiConsoleUI {
|
|||||||
}
|
}
|
||||||
textGraphics = terminal.newTextGraphics()
|
textGraphics = terminal.newTextGraphics()
|
||||||
|
|
||||||
|
/*
|
||||||
|
var lastRedrawTime = 0L
|
||||||
|
var lastNewWidth = 0
|
||||||
|
var lastNewHeight = 0
|
||||||
|
|
||||||
terminal.addResizeListener(TerminalResizeListener { terminal1: Terminal, newSize: TerminalSize ->
|
terminal.addResizeListener(TerminalResizeListener { terminal1: Terminal, newSize: TerminalSize ->
|
||||||
terminal.clearScreen()
|
try {
|
||||||
inited = false
|
if (lastNewHeight == newSize.rows
|
||||||
update()
|
&&
|
||||||
redrawCommand()
|
lastNewWidth == newSize.columns
|
||||||
redrawLogs(log[screens[currentScreenId]]!!)
|
) {
|
||||||
|
return@TerminalResizeListener
|
||||||
|
}
|
||||||
|
lastNewHeight = newSize.rows
|
||||||
|
lastNewWidth = newSize.columns
|
||||||
|
terminal.clearScreen()
|
||||||
|
if(terminal !is SwingTerminalFrame) {
|
||||||
|
Thread.sleep(300)
|
||||||
|
}
|
||||||
|
update()
|
||||||
|
redrawCommand()
|
||||||
|
redrawLogs(log[screens[currentScreenId]]!!)
|
||||||
|
}catch (ignored:Exception){
|
||||||
|
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
*/
|
||||||
|
var lastJob: Job? = null
|
||||||
|
terminal.addResizeListener(TerminalResizeListener { terminal1: Terminal, newSize: TerminalSize ->
|
||||||
|
lastJob = GlobalScope.launch {
|
||||||
|
delay(300)
|
||||||
|
if (lastJob == coroutineContext[Job]) {
|
||||||
|
terminal.clearScreen()
|
||||||
|
//inited = false
|
||||||
|
update()
|
||||||
|
redrawCommand()
|
||||||
|
redrawLogs(log[screens[currentScreenId]]!!)
|
||||||
|
}
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
if (terminal !is SwingTerminalFrame) {
|
if (terminal !is SwingTerminalFrame) {
|
||||||
@ -104,10 +143,14 @@ object MiraiConsoleUI {
|
|||||||
when (keyStroke.keyType) {
|
when (keyStroke.keyType) {
|
||||||
KeyType.ArrowLeft -> {
|
KeyType.ArrowLeft -> {
|
||||||
currentScreenId = getLeftScreenId()
|
currentScreenId = getLeftScreenId()
|
||||||
|
clearRows(2)
|
||||||
|
cleanPage()
|
||||||
update()
|
update()
|
||||||
}
|
}
|
||||||
KeyType.ArrowRight -> {
|
KeyType.ArrowRight -> {
|
||||||
currentScreenId = getRightScreenId()
|
currentScreenId = getRightScreenId()
|
||||||
|
clearRows(2)
|
||||||
|
cleanPage()
|
||||||
update()
|
update()
|
||||||
}
|
}
|
||||||
KeyType.Enter -> {
|
KeyType.Enter -> {
|
||||||
@ -156,7 +199,6 @@ object MiraiConsoleUI {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
var inited = false
|
|
||||||
fun clearRows(row: Int) {
|
fun clearRows(row: Int) {
|
||||||
textGraphics.putString(0, row, " ".repeat(terminal.terminalSize.columns))
|
textGraphics.putString(0, row, " ".repeat(terminal.terminalSize.columns))
|
||||||
}
|
}
|
||||||
@ -167,25 +209,24 @@ object MiraiConsoleUI {
|
|||||||
val width = terminal.terminalSize.columns
|
val width = terminal.terminalSize.columns
|
||||||
val height = terminal.terminalSize.rows
|
val height = terminal.terminalSize.rows
|
||||||
terminal.setBackgroundColor(TextColor.ANSI.DEFAULT)
|
terminal.setBackgroundColor(TextColor.ANSI.DEFAULT)
|
||||||
if (!inited) {
|
|
||||||
val mainTitle = "Mirai Console v0.01 Core v0.15"
|
val mainTitle = "Mirai Console v0.01 Core v0.15"
|
||||||
textGraphics.foregroundColor = TextColor.ANSI.WHITE
|
textGraphics.foregroundColor = TextColor.ANSI.WHITE
|
||||||
textGraphics.backgroundColor = TextColor.ANSI.GREEN
|
textGraphics.backgroundColor = TextColor.ANSI.GREEN
|
||||||
textGraphics.putString((width - mainTitle.length) / 2, 1, mainTitle, SGR.BOLD)
|
textGraphics.putString((width - mainTitle.length) / 2, 1, mainTitle, SGR.BOLD)
|
||||||
textGraphics.foregroundColor = TextColor.ANSI.DEFAULT
|
textGraphics.foregroundColor = TextColor.ANSI.DEFAULT
|
||||||
textGraphics.backgroundColor = TextColor.ANSI.DEFAULT
|
textGraphics.backgroundColor = TextColor.ANSI.DEFAULT
|
||||||
textGraphics.putString(2, 3, "-".repeat(width - 4))
|
textGraphics.putString(2, 3, "-".repeat(width - 4))
|
||||||
textGraphics.putString(2, 5, "-".repeat(width - 4))
|
textGraphics.putString(2, 5, "-".repeat(width - 4))
|
||||||
textGraphics.putString(2, height - 4, "-".repeat(width - 4))
|
textGraphics.putString(2, height - 4, "-".repeat(width - 4))
|
||||||
textGraphics.putString(2, height - 3, "|>>>")
|
textGraphics.putString(2, height - 3, "|>>>")
|
||||||
textGraphics.putString(width - 3, height - 3, "|")
|
textGraphics.putString(width - 3, height - 3, "|")
|
||||||
textGraphics.putString(2, height - 2, "-".repeat(width - 4))
|
textGraphics.putString(2, height - 2, "-".repeat(width - 4))
|
||||||
inited = true
|
|
||||||
}
|
|
||||||
textGraphics.foregroundColor = TextColor.ANSI.DEFAULT
|
textGraphics.foregroundColor = TextColor.ANSI.DEFAULT
|
||||||
textGraphics.backgroundColor = TextColor.ANSI.DEFAULT
|
textGraphics.backgroundColor = TextColor.ANSI.DEFAULT
|
||||||
val leftName = getScreenName(getLeftScreenId())
|
val leftName = getScreenName(getLeftScreenId())
|
||||||
clearRows(2)
|
// clearRows(2)
|
||||||
textGraphics.putString((width - title.length) / 2 - "$leftName << ".length, 2, "$leftName << ")
|
textGraphics.putString((width - title.length) / 2 - "$leftName << ".length, 2, "$leftName << ")
|
||||||
textGraphics.foregroundColor = TextColor.ANSI.WHITE
|
textGraphics.foregroundColor = TextColor.ANSI.WHITE
|
||||||
textGraphics.backgroundColor = TextColor.ANSI.YELLOW
|
textGraphics.backgroundColor = TextColor.ANSI.YELLOW
|
||||||
@ -230,14 +271,14 @@ object MiraiConsoleUI {
|
|||||||
var currentHeight = 6
|
var currentHeight = 6
|
||||||
|
|
||||||
fun drawLog(string: String, flush: Boolean = true) {
|
fun drawLog(string: String, flush: Boolean = true) {
|
||||||
val maxHeight = terminal.terminalSize.rows - 6
|
val maxHeight = terminal.terminalSize.rows - 4
|
||||||
val heightNeed = (string.length / (terminal.terminalSize.columns - 6)) + 1
|
val heightNeed = (string.length / (terminal.terminalSize.columns - 6)) + 1
|
||||||
if (currentHeight + heightNeed > maxHeight) {
|
if (currentHeight + heightNeed > maxHeight) {
|
||||||
cleanPage()
|
cleanPage()
|
||||||
}
|
}
|
||||||
textGraphics.foregroundColor = TextColor.ANSI.GREEN
|
textGraphics.foregroundColor = TextColor.ANSI.GREEN
|
||||||
textGraphics.backgroundColor = TextColor.ANSI.DEFAULT
|
textGraphics.backgroundColor = TextColor.ANSI.DEFAULT
|
||||||
val width = terminal.terminalSize.columns - 6
|
val width = terminal.terminalSize.columns - 7
|
||||||
var x = string
|
var x = string
|
||||||
while (true) {
|
while (true) {
|
||||||
if (x == "") break
|
if (x == "") break
|
||||||
@ -264,7 +305,7 @@ object MiraiConsoleUI {
|
|||||||
|
|
||||||
|
|
||||||
fun cleanPage() {
|
fun cleanPage() {
|
||||||
for (index in 6 until terminal.terminalSize.rows - 6) {
|
for (index in 6 until terminal.terminalSize.rows - 4) {
|
||||||
clearRows(index)
|
clearRows(index)
|
||||||
}
|
}
|
||||||
currentHeight = 6
|
currentHeight = 6
|
||||||
@ -272,20 +313,21 @@ object MiraiConsoleUI {
|
|||||||
|
|
||||||
|
|
||||||
fun redrawLogs(toDraw: List<String>) {
|
fun redrawLogs(toDraw: List<String>) {
|
||||||
this.cleanPage()
|
//this.cleanPage()
|
||||||
|
currentHeight = 6
|
||||||
var logsToDraw = 0
|
var logsToDraw = 0
|
||||||
var vara = 0
|
var vara = 0
|
||||||
toDraw.reversed().forEach {
|
toDraw.forEach {
|
||||||
val heightNeed = (it.length / (terminal.terminalSize.columns - 6)) + 1
|
val heightNeed = (it.length / (terminal.terminalSize.columns - 6)) + 1
|
||||||
vara += heightNeed
|
vara += heightNeed
|
||||||
if (currentHeight + vara < terminal.terminalSize.rows - 6) {
|
if (currentHeight + vara < terminal.terminalSize.rows - 4) {
|
||||||
logsToDraw++
|
logsToDraw++
|
||||||
} else {
|
} else {
|
||||||
return
|
return@forEach
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (index in (toDraw.size - logsToDraw) until toDraw.size - 1) {
|
for (index in 0 until logsToDraw) {
|
||||||
drawLog(toDraw[index], false)
|
drawLog(toDraw[logsToDraw - index - 1], false)
|
||||||
}
|
}
|
||||||
if (terminal is SwingTerminalFrame) {
|
if (terminal is SwingTerminalFrame) {
|
||||||
terminal.flush()
|
terminal.flush()
|
||||||
|
Loading…
Reference in New Issue
Block a user