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