Explorar o código

Graphical log color

ryoii %!s(int64=6) %!d(string=hai) anos
pai
achega
25083f8b2e

+ 2 - 2
mirai-console-graphical/src/main/kotlin/net/mamoe/mirai/console/graphical/controller/MiraiGraphicalUIController.kt

@@ -27,7 +27,7 @@ class MiraiGraphicalUIController : Controller(), MiraiConsoleUI {
     private val settingModel = find<GlobalSettingModel>()
     private val loginSolver = GraphicalLoginSolver()
     private val cache = mutableMapOf<Long, BotModel>()
-    val mainLog = observableListOf<String>()
+    val mainLog = observableListOf<Pair<String, String>>()
 
 
     val botList = observableListOf<BotModel>()
@@ -69,7 +69,7 @@ class MiraiGraphicalUIController : Controller(), MiraiConsoleUI {
             } else {
                 cache[identity]?.logHistory
             }?.apply {
-                add("[$time] $identityStr $message")
+                add("[$time] $identityStr $message" to priority.name)
                 trim()
             }
         }

+ 1 - 1
mirai-console-graphical/src/main/kotlin/net/mamoe/mirai/console/graphical/model/BotModel.kt

@@ -11,7 +11,7 @@ class BotModel(val uin: Long) {
     val botProperty = SimpleObjectProperty<Bot>(null)
     var bot: Bot by botProperty
 
-    val logHistory = observableListOf<String>()
+    val logHistory = observableListOf<Pair<String, String>>()
     val admins = observableListOf<Long>()
 }
 

+ 9 - 0
mirai-console-graphical/src/main/kotlin/net/mamoe/mirai/console/graphical/stylesheet/PrimaryStyleSheet.kt

@@ -124,6 +124,15 @@ class PrimaryStyleSheet : BaseStyleSheet() {
                 }
 
                 listCell {
+
+                    and(":WARNING") {
+                        backgroundColor += c("FFFF00", 0.3) // Yellow
+                    }
+
+                    and(":ERROR") {
+                        backgroundColor += c("FF0000", 0.3) // Red
+                    }
+
                     and(":selected") {
                         backgroundColor += c(stressColor, 1.0)
                     }

+ 6 - 3
mirai-console-graphical/src/main/kotlin/net/mamoe/mirai/console/graphical/view/PrimaryView.kt

@@ -151,7 +151,7 @@ private fun TabPane.fixedTab(title: String) = tab(title) { isClosable = false }
 
 private fun TabPane.logTab(
     text: String? = null,
-    logs: ObservableList<String>,
+    logs: ObservableList<Pair<String, String>>,
     closeable: Boolean = true,
     op: Tab.() -> Unit = {}
 ) = tab(text) {
@@ -174,7 +174,7 @@ private fun TabPane.logTab(
                     path.firstOrNull()?.run {
                         if (!exists()) createNewFile()
                         writer().use {
-                            logs.forEach { log -> it.appendln(log) }
+                            logs.forEach { log -> it.appendln(log.first) }
                         }
                         true
                     } ?: false
@@ -188,7 +188,10 @@ private fun TabPane.logTab(
 
             fitToParentSize()
             cellFormat {
-                graphic = label(it) {
+
+                addPseudoClass(it.second)
+
+                graphic = label(it.first) {
                     maxWidthProperty().bind([email protected]())
                     isWrapText = true
                 }