mirror of
https://github.com/mamoe/mirai.git
synced 2025-03-06 17:10:48 +08:00
Merge remote-tracking branch 'origin'
This commit is contained in:
commit
bcf6a2a9aa
@ -237,7 +237,7 @@ object MiraiConsole {
|
|||||||
object CommandListener {
|
object CommandListener {
|
||||||
fun start() {
|
fun start() {
|
||||||
thread {
|
thread {
|
||||||
processNextCommandLine()
|
//processNextCommandLine()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -281,7 +281,6 @@ class MiraiConsoleLoader {
|
|||||||
companion object {
|
companion object {
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun main(args: Array<String>) {
|
fun main(args: Array<String>) {
|
||||||
|
|
||||||
MiraiConsole.start()
|
MiraiConsole.start()
|
||||||
Runtime.getRuntime().addShutdownHook(thread(start = false) {
|
Runtime.getRuntime().addShutdownHook(thread(start = false) {
|
||||||
MiraiConsole.stop()
|
MiraiConsole.stop()
|
||||||
|
@ -11,11 +11,15 @@ 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 net.mamoe.mirai.MiraiConsoleUI.LoggerDrawer.drawLog
|
||||||
|
import net.mamoe.mirai.MiraiConsoleUI.LoggerDrawer.redrawLogs
|
||||||
|
import net.mamoe.mirai.utils.currentTimeSeconds
|
||||||
import java.io.OutputStream
|
import java.io.OutputStream
|
||||||
import java.io.PrintStream
|
import java.io.PrintStream
|
||||||
import java.lang.StringBuilder
|
import java.nio.charset.Charset
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import kotlin.concurrent.thread
|
import kotlin.concurrent.thread
|
||||||
|
import kotlin.math.ceil
|
||||||
|
|
||||||
|
|
||||||
object MiraiConsoleUI {
|
object MiraiConsoleUI {
|
||||||
@ -36,12 +40,17 @@ object MiraiConsoleUI {
|
|||||||
lateinit var textGraphics: TextGraphics
|
lateinit var textGraphics: TextGraphics
|
||||||
|
|
||||||
var hasStart = false
|
var hasStart = false
|
||||||
|
private lateinit var internalPrinter: PrintStream
|
||||||
fun start() {
|
fun start() {
|
||||||
if (hasStart) {
|
if (hasStart) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internalPrinter = System.out
|
||||||
|
|
||||||
|
|
||||||
hasStart = true
|
hasStart = true
|
||||||
val defaultTerminalFactory = DefaultTerminalFactory()
|
val defaultTerminalFactory = DefaultTerminalFactory(internalPrinter, System.`in`, Charset.defaultCharset())
|
||||||
try {
|
try {
|
||||||
terminal = defaultTerminalFactory.createTerminal()
|
terminal = defaultTerminalFactory.createTerminal()
|
||||||
terminal.enterPrivateMode()
|
terminal.enterPrivateMode()
|
||||||
@ -64,8 +73,27 @@ object MiraiConsoleUI {
|
|||||||
inited = false
|
inited = false
|
||||||
update()
|
update()
|
||||||
redrawCommand()
|
redrawCommand()
|
||||||
|
redrawLogs(log[screens[currentScreenId]]!!)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
if (terminal !is SwingTerminalFrame) {
|
||||||
|
System.setOut(PrintStream(object : OutputStream() {
|
||||||
|
var builder = java.lang.StringBuilder()
|
||||||
|
override fun write(b: Int) {
|
||||||
|
with(b.toChar()) {
|
||||||
|
if (this == '\n') {
|
||||||
|
pushLog(0, builder.toString())
|
||||||
|
builder = java.lang.StringBuilder()
|
||||||
|
} else {
|
||||||
|
builder.append(this)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
|
||||||
|
System.setErr(System.out)
|
||||||
|
|
||||||
update()
|
update()
|
||||||
|
|
||||||
val charList = listOf(',', '.', '/', '@', '#', '$', '%', '^', '&', '*', '(', ')', '_', '=', '+', '!', ' ')
|
val charList = listOf(',', '.', '/', '@', '#', '$', '%', '^', '&', '*', '(', ')', '_', '=', '+', '!', ' ')
|
||||||
@ -197,52 +225,83 @@ object MiraiConsoleUI {
|
|||||||
textGraphics.putString(width - 2 - "Add admins via commands|".length, 4, "Add admins via commands|")
|
textGraphics.putString(width - 2 - "Add admins via commands|".length, 4, "Add admins via commands|")
|
||||||
}
|
}
|
||||||
|
|
||||||
fun drawLogs(values: List<String>) {
|
|
||||||
val width = terminal.terminalSize.columns - 6
|
|
||||||
val heightMin = 5
|
|
||||||
|
|
||||||
var currentHeight = terminal.terminalSize.rows - 5
|
object LoggerDrawer {
|
||||||
|
var currentHeight = 6
|
||||||
|
|
||||||
for (index in heightMin until currentHeight) {
|
fun drawLog(string: String, flush: Boolean = true) {
|
||||||
clearRows(index)
|
val maxHeight = terminal.terminalSize.rows - 6
|
||||||
}
|
val heightNeed = (string.length / (terminal.terminalSize.columns - 6)) + 1
|
||||||
|
if (currentHeight + heightNeed > maxHeight) {
|
||||||
values.forEach {
|
cleanPage()
|
||||||
if (currentHeight > heightMin) {
|
}
|
||||||
var x = it
|
textGraphics.foregroundColor = TextColor.ANSI.GREEN
|
||||||
while (currentHeight > heightMin) {
|
textGraphics.backgroundColor = TextColor.ANSI.DEFAULT
|
||||||
if (x.isEmpty() || x.isBlank()) break
|
val width = terminal.terminalSize.columns - 6
|
||||||
textGraphics.foregroundColor = TextColor.ANSI.GREEN
|
var x = string
|
||||||
textGraphics.backgroundColor = TextColor.ANSI.DEFAULT
|
while (true) {
|
||||||
val towrite = if (x.length > width) {
|
if (x == "") break
|
||||||
x.substring(0, width).also {
|
val toWrite = if (x.length > width) {
|
||||||
x = x.substring(width)
|
x.substring(0, width).also {
|
||||||
}
|
x = x.substring(width)
|
||||||
} else {
|
}
|
||||||
x.also {
|
} else {
|
||||||
x = ""
|
x.also {
|
||||||
}
|
x = ""
|
||||||
}
|
}
|
||||||
textGraphics.putString(3, currentHeight, towrite, SGR.ITALIC)
|
|
||||||
--currentHeight
|
|
||||||
}
|
}
|
||||||
|
try {
|
||||||
|
textGraphics.putString(3, currentHeight, toWrite, SGR.ITALIC)
|
||||||
|
} catch (ignored: Exception) {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
++currentHeight
|
||||||
|
}
|
||||||
|
if (flush && terminal is SwingTerminalFrame) {
|
||||||
|
terminal.flush()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
textGraphics.putString(3, 9, "AAAAAAAAAAAAAAAAAAAAAAa", SGR.ITALIC)
|
|
||||||
terminal.flush()
|
fun cleanPage() {
|
||||||
|
for (index in 6 until terminal.terminalSize.rows - 6) {
|
||||||
|
clearRows(index)
|
||||||
|
}
|
||||||
|
currentHeight = 6
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
fun redrawLogs(toDraw: List<String>) {
|
||||||
|
this.cleanPage()
|
||||||
|
var logsToDraw = 0
|
||||||
|
var vara = 0
|
||||||
|
toDraw.reversed().forEach {
|
||||||
|
val heightNeed = (it.length / (terminal.terminalSize.columns - 6)) + 1
|
||||||
|
vara += heightNeed
|
||||||
|
if (currentHeight + vara < terminal.terminalSize.rows - 6) {
|
||||||
|
logsToDraw++
|
||||||
|
} else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (index in (toDraw.size - logsToDraw) until toDraw.size - 1) {
|
||||||
|
drawLog(toDraw[index], false)
|
||||||
|
}
|
||||||
|
if (terminal is SwingTerminalFrame) {
|
||||||
|
terminal.flush()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun pushLog(uin: Long, str: String) {
|
fun pushLog(uin: Long, str: String) {
|
||||||
log[uin]!!.push(str)
|
log[uin]!!.push(str)
|
||||||
if (uin == screens[currentScreenId]) {
|
if (uin == screens[currentScreenId]) {
|
||||||
drawLogs(log[screens[currentScreenId]]!!)
|
drawLog(str)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
var commandBuilder = StringBuilder()
|
var commandBuilder = StringBuilder()
|
||||||
|
|
||||||
fun redrawCommand() {
|
fun redrawCommand() {
|
||||||
val height = terminal.terminalSize.rows
|
val height = terminal.terminalSize.rows
|
||||||
val width = terminal.terminalSize.columns
|
val width = terminal.terminalSize.columns
|
||||||
@ -303,7 +362,7 @@ object MiraiConsoleUI {
|
|||||||
drawBotFrame(screens[currentScreenId], 0)
|
drawBotFrame(screens[currentScreenId], 0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
terminal.flush()
|
redrawLogs(log[screens[currentScreenId]]!!)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -215,7 +215,7 @@ fun ByteReadPacket.readIoBuffer(
|
|||||||
* 解析 SSO 层包装
|
* 解析 SSO 层包装
|
||||||
*/
|
*/
|
||||||
@UseExperimental(ExperimentalUnsignedTypes::class)
|
@UseExperimental(ExperimentalUnsignedTypes::class)
|
||||||
private fun parseSsoFrame(flag3: Int, input: ByteReadPacket): KnownPacketFactories.IncomingPacket {
|
private fun parseSsoFrame(flag3: Int, input: ByteReadPacket): KnownPacketFactories.IncomingPacket<*> {
|
||||||
val commandName: String
|
val commandName: String
|
||||||
val ssoSequenceId: Int
|
val ssoSequenceId: Int
|
||||||
|
|
||||||
@ -257,7 +257,7 @@ private fun parseSsoFrame(flag3: Int, input: ByteReadPacket): KnownPacketFactori
|
|||||||
* 解析 Uni 层包装
|
* 解析 Uni 层包装
|
||||||
*/
|
*/
|
||||||
@UseExperimental(ExperimentalUnsignedTypes::class)
|
@UseExperimental(ExperimentalUnsignedTypes::class)
|
||||||
private fun parseUniFrame(input: ByteReadPacket): KnownPacketFactories.IncomingPacket {
|
private fun parseUniFrame(input: ByteReadPacket): KnownPacketFactories.IncomingPacket<*> {
|
||||||
// 00 00 00 30 00 01 2F 7C 00 00 00 00 00 00 00 04 00 00 00 14 67 78 68 72 65 70 6F 72 74 2E 72 65 70 6F 72 74 00 00 00 08 66 82 D3 0B 00 00 00 00
|
// 00 00 00 30 00 01 2F 7C 00 00 00 00 00 00 00 04 00 00 00 14 67 78 68 72 65 70 6F 72 74 2E 72 65 70 6F 72 74 00 00 00 08 66 82 D3 0B 00 00 00 00
|
||||||
// 00 00 00 06 08 00
|
// 00 00 00 06 08 00
|
||||||
|
|
||||||
|
@ -5,6 +5,10 @@ Mirai Java Apt
|
|||||||
|
|
||||||
提供阻塞API 来让 Java 调用 Mirai 的 API 更容易
|
提供阻塞API 来让 Java 调用 Mirai 的 API 更容易
|
||||||
|
|
||||||
|
## Requirements
|
||||||
|
|
||||||
|
- JDK 1.8+
|
||||||
|
|
||||||
## 开始
|
## 开始
|
||||||
|
|
||||||
```java
|
```java
|
||||||
|
Loading…
Reference in New Issue
Block a user