Drop ansi

This commit is contained in:
Karlatemp 2020-09-11 19:45:26 +08:00
parent 12b942a27b
commit 6f38654f87
No known key found for this signature in database
GPG Key ID: 21FBDDF664FF06F8
2 changed files with 8 additions and 3 deletions

View File

@ -37,6 +37,7 @@ public object ConsolePureSettings {
@JvmField
var dropAnsi = false
@JvmField
var noConsoleSafeReading=false
var noConsoleSafeReading = false
}

View File

@ -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)