mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-25 15:40:28 +08:00
Drop ansi
This commit is contained in:
parent
12b942a27b
commit
6f38654f87
@ -37,6 +37,7 @@ public object ConsolePureSettings {
|
||||
|
||||
@JvmField
|
||||
var dropAnsi = false
|
||||
|
||||
@JvmField
|
||||
var noConsoleSafeReading=false
|
||||
var noConsoleSafeReading = false
|
||||
}
|
@ -10,6 +10,7 @@
|
||||
/*
|
||||
* @author Karlatemp <karlatemp@vip.qq.com> <https://github.com/Karlatemp>
|
||||
*/
|
||||
@file:OptIn(ConsolePureExperimentalAPI::class)
|
||||
|
||||
package net.mamoe.mirai.console.pure.noconsole
|
||||
|
||||
@ -82,20 +83,23 @@ internal object AllIgnoredOutputStream : OutputStream() {
|
||||
}
|
||||
}
|
||||
|
||||
@OptIn(ConsolePureExperimentalAPI::class)
|
||||
internal val SystemOutputPrintStream by lazy {
|
||||
if (ConsolePureSettings.setupAnsi) {
|
||||
org.fusesource.jansi.AnsiConsole.systemInstall()
|
||||
}
|
||||
System.out
|
||||
}
|
||||
private val ANSI_REGEX = """\u001b\[[0-9a-zA-Z;]*?m""".toRegex()
|
||||
|
||||
internal object AllEmptyLineReader : LineReader {
|
||||
private fun <T> ignored(): T = error("Ignored")
|
||||
override fun defaultKeyMaps(): MutableMap<String, KeyMap<Binding>> = ignored()
|
||||
|
||||
override fun printAbove(str: String?) {
|
||||
SystemOutputPrintStream.println(str)
|
||||
if (str == null) return
|
||||
if (ConsolePureSettings.dropAnsi) {
|
||||
SystemOutputPrintStream.println(ANSI_REGEX.replace(str, ""))
|
||||
} else SystemOutputPrintStream.println(str)
|
||||
}
|
||||
|
||||
@OptIn(ConsolePureExperimentalAPI::class)
|
||||
|
Loading…
Reference in New Issue
Block a user