Skip to content

Commit ec56888

Browse files
author
54895y
committed
Add plugin-specific Chinese console banners
1 parent 72edc68 commit ec56888

3 files changed

Lines changed: 95 additions & 34 deletions

File tree

src/main/kotlin/com/y54895/matrixlib/MatrixLib.kt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,16 @@ object MatrixLib : Plugin() {
1111
val branding = MatrixBranding(
1212
displayName = "MatrixLib",
1313
rootCommand = "/matrixlib",
14-
runtimeName = "Matrix shared service bus"
14+
runtimeName = "MatrixLib 共享运行时"
1515
)
1616

1717
override fun onLoad() {
1818
MatrixConsoleVisuals.renderBoot(
1919
branding = branding,
20-
headline = "Loading shared Matrix runtime",
20+
headline = "正在装载共享接口与运行时桥接",
2121
details = listOf(
22-
MatrixConsoleFact("Exports", "action / menu / compat / text / yaml / console"),
23-
MatrixConsoleFact("Usage", "Required by MatrixShop, MatrixAuth, MatrixCook")
22+
MatrixConsoleFact("导出接口", "action / menu / compat / text / yaml / console"),
23+
MatrixConsoleFact("服务对象", "MatrixShop / MatrixAuth / MatrixCook")
2424
)
2525
)
2626
}
@@ -30,8 +30,8 @@ object MatrixLib : Plugin() {
3030
branding = branding,
3131
version = pluginVersion,
3232
details = listOf(
33-
MatrixConsoleFact("API", "Action, menu, compat, text, yaml"),
34-
MatrixConsoleFact("Runtime", "Console visuals and resource bridge")
33+
MatrixConsoleFact("共享接口", "action / menu / compat / text / yaml / console"),
34+
MatrixConsoleFact("运行状态", "控制台品牌 / 资源桥接 / 通用适配")
3535
)
3636
)
3737
}
@@ -40,7 +40,7 @@ object MatrixLib : Plugin() {
4040
MatrixConsoleVisuals.renderShutdown(
4141
branding = branding,
4242
details = listOf(
43-
MatrixConsoleFact("State", "Shared runtime offline")
43+
MatrixConsoleFact("运行状态", "共享运行时已离线")
4444
)
4545
)
4646
}

src/main/kotlin/com/y54895/matrixlib/api/brand/MatrixBranding.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@ data class MatrixBranding(
66
val adminCommand: String? = null,
77
val runtimeName: String = displayName,
88
val accentColor: String = "&b",
9-
val neutralColor: String = "&7"
9+
val neutralColor: String = "&7",
10+
val bannerTitle: String = displayName
1011
)

src/main/kotlin/com/y54895/matrixlib/api/console/MatrixConsoleVisuals.kt

Lines changed: 86 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,8 @@ data class MatrixConsoleFact(
1212

1313
object MatrixConsoleVisuals {
1414

15-
private const val BORDER = "&8&m+------------------------------------------------------------------+"
16-
17-
private val logo = listOf(
18-
"&3 __ __ _ _ __ __ _ _ ",
19-
"&b| \\/ | __ _| |_ _ __(_)_ __ | \\/ | __ _| |_ _ __(_)_ __",
20-
"&b| |\\/| |/ _` | __| '__| \\ \\/ / | |\\/| |/ _` | __| '__| \\ \\/ /",
21-
"&9| | | | (_| | |_| | | |> < | | | | (_| | |_| | | |> < ",
22-
"&9|_| |_|\\__,_|\\__|_| |_/_/\\_\\ |_| |_|\\__,_|\\__|_| |_/_/\\_\\"
23-
)
15+
private const val MIN_BORDER_WIDTH = 66
16+
private val colorCodePattern = Regex("&[0-9a-fk-orA-FK-OR]")
2417

2518
fun renderBoot(
2619
branding: MatrixBranding,
@@ -59,8 +52,8 @@ object MatrixConsoleVisuals {
5952
renderBlock(
6053
branding = branding,
6154
stage = "READY",
62-
headline = "${branding.runtimeName} online",
63-
details = listOf(MatrixConsoleFact("Version", version)) + defaultDetails(branding) + details,
55+
headline = "${branding.runtimeName} 已就绪",
56+
details = listOf(MatrixConsoleFact("版本", version)) + defaultDetails(branding) + details,
6457
trailingBlank = true
6558
)
6659
}
@@ -72,8 +65,8 @@ object MatrixConsoleVisuals {
7265
renderBlock(
7366
branding = branding,
7467
stage = "FAIL",
75-
headline = "${branding.runtimeName} startup aborted",
76-
details = listOf(MatrixConsoleFact("Reason", reason))
68+
headline = "${branding.runtimeName} 启动失败",
69+
details = listOf(MatrixConsoleFact("原因", reason))
7770
)
7871
}
7972

@@ -84,7 +77,7 @@ object MatrixConsoleVisuals {
8477
renderBlock(
8578
branding = branding,
8679
stage = "STOP",
87-
headline = "${branding.runtimeName} shutting down",
80+
headline = "${branding.runtimeName} 正在卸载",
8881
details = details,
8982
leadingBlank = true
9083
)
@@ -99,28 +92,31 @@ object MatrixConsoleVisuals {
9992
leadingBlank: Boolean = false,
10093
trailingBlank: Boolean = false
10194
) {
95+
val contentLines = mutableListOf<String>()
96+
if (includeLogo) {
97+
contentLines += MatrixAsciiBanner.render(branding.bannerTitle)
98+
contentLines += stageLine(branding, "INFO", branding.runtimeName)
99+
}
100+
contentLines += stageLine(branding, stage, headline)
101+
details.forEach { contentLines += detailLine(branding, it) }
102+
103+
val border = border(contentLines)
102104
val lines = mutableListOf<String>()
103105
if (leadingBlank) {
104106
lines += ""
105107
}
106-
lines += BORDER
107-
if (includeLogo) {
108-
lines += logo
109-
lines += stageLine(branding, "INFO", branding.runtimeName)
110-
lines += BORDER
111-
}
112-
lines += stageLine(branding, stage, headline)
113-
details.forEach { lines += detailLine(branding, it) }
114-
lines += BORDER
108+
lines += border
109+
contentLines.forEach { lines += it }
110+
lines += border
115111
if (trailingBlank) {
116112
lines += ""
117113
}
118114
send(lines)
119115
}
120116

121117
private fun defaultDetails(branding: MatrixBranding): List<MatrixConsoleFact> {
122-
val details = mutableListOf(MatrixConsoleFact("Command", branding.rootCommand))
123-
branding.adminCommand?.let { details += MatrixConsoleFact("Admin", it) }
118+
val details = mutableListOf(MatrixConsoleFact("主命令", branding.rootCommand))
119+
branding.adminCommand?.let { details += MatrixConsoleFact("管理命令", it) }
124120
return details
125121
}
126122

@@ -131,7 +127,7 @@ object MatrixConsoleVisuals {
131127
"FAIL", "STOP" -> "&c"
132128
else -> branding.accentColor
133129
}
134-
return "${prefix(branding)}$color[$stage] &f$headline"
130+
return "${prefix(branding)}$color[${stageLabel(stage)}] &f$headline"
135131
}
136132

137133
private fun detailLine(branding: MatrixBranding, fact: MatrixConsoleFact): String {
@@ -142,6 +138,27 @@ object MatrixConsoleVisuals {
142138
return "&8[${branding.accentColor}${branding.displayName}&8] "
143139
}
144140

141+
private fun stageLabel(stage: String): String {
142+
return when (stage.uppercase()) {
143+
"INFO" -> "信息"
144+
"LOAD" -> "加载"
145+
"INIT" -> "初始化"
146+
"READY" -> "就绪"
147+
"FAIL" -> "失败"
148+
"STOP" -> "卸载"
149+
else -> stage
150+
}
151+
}
152+
153+
private fun border(lines: List<String>): String {
154+
val width = maxOf(MIN_BORDER_WIDTH, lines.maxOfOrNull(::visibleLength) ?: MIN_BORDER_WIDTH)
155+
return "&8&m+${"-".repeat(width)}+"
156+
}
157+
158+
private fun visibleLength(line: String): Int {
159+
return colorCodePattern.replace(line, "").length
160+
}
161+
145162
private fun send(lines: List<String>) {
146163
lines.forEach { line ->
147164
val rendered = MatrixText.color(line)
@@ -153,3 +170,46 @@ object MatrixConsoleVisuals {
153170
}
154171
}
155172
}
173+
174+
private object MatrixAsciiBanner {
175+
176+
private val rowColors = listOf("&3", "&b", "&b", "&9", "&9")
177+
178+
private val glyphs = mapOf(
179+
' ' to listOf(" ", " ", " ", " ", " "),
180+
'?' to listOf("?????", " ? ", " ? ", " ", " ? "),
181+
'A' to listOf(" A ", " A A ", "AAAAA", "A A", "A A"),
182+
'B' to listOf("BBBB ", "B B", "BBBB ", "B B", "BBBB "),
183+
'C' to listOf(" CCC ", "C C", "C ", "C C", " CCC "),
184+
'H' to listOf("H H", "H H", "HHHHH", "H H", "H H"),
185+
'I' to listOf("IIIII", " I ", " I ", " I ", "IIIII"),
186+
'K' to listOf("K K", "K K ", "KKK ", "K K ", "K K"),
187+
'L' to listOf("L ", "L ", "L ", "L ", "LLLLL"),
188+
'M' to listOf("M M", "MM MM", "M M M", "M M", "M M"),
189+
'N' to listOf("N N", "NN N", "N N N", "N NN", "N N"),
190+
'O' to listOf(" OOO ", "O O", "O O", "O O", " OOO "),
191+
'P' to listOf("PPPP ", "P P", "PPPP ", "P ", "P "),
192+
'R' to listOf("RRRR ", "R R", "RRRR ", "R R ", "R R"),
193+
'S' to listOf(" SSS ", "S ", " SSS ", " S", " SSS "),
194+
'T' to listOf("TTTTT", " T ", " T ", " T ", " T "),
195+
'U' to listOf("U U", "U U", "U U", "U U", " UUU "),
196+
'X' to listOf("X X", " X X ", " X ", " X X ", "X X")
197+
)
198+
199+
fun render(text: String): List<String> {
200+
val normalized = text.uppercase().ifBlank { "MATRIX" }
201+
val rows = List(rowColors.size) { StringBuilder() }
202+
normalized.forEachIndexed { index, char ->
203+
val glyph = glyphs[char] ?: glyphs.getValue('?')
204+
glyph.forEachIndexed { rowIndex, row ->
205+
rows[rowIndex].append(row)
206+
if (index < normalized.lastIndex) {
207+
rows[rowIndex].append(' ')
208+
}
209+
}
210+
}
211+
return rows.mapIndexed { index, builder ->
212+
rowColors[index] + builder.toString().trimEnd()
213+
}
214+
}
215+
}

0 commit comments

Comments
 (0)