forked from StarOpenSource/Engine
Fix ANSI formatting issues
This commit is contained in:
parent
687631661d
commit
c640176dd7
1 changed files with 19 additions and 18 deletions
|
@ -55,13 +55,14 @@ class AnsiFormatter : TwoCycleFormatterImpl() {
|
||||||
override fun format(messageComponents: Array<String>): String = buildString {
|
override fun format(messageComponents: Array<String>): String = buildString {
|
||||||
val enabledTags: MutableSet<String> = mutableSetOf()
|
val enabledTags: MutableSet<String> = mutableSetOf()
|
||||||
var lastColor: String? = null
|
var lastColor: String? = null
|
||||||
var modifiers: String = "0;"
|
var modifiers: String = ""
|
||||||
|
|
||||||
for (component: String in messageComponents)
|
for (component: String in messageComponents)
|
||||||
// Reset
|
// Reset
|
||||||
if (component == "RESET") {
|
if (component == "RESET") {
|
||||||
append("${ESCAPE}[0m")
|
append("${ESCAPE}[0;39;49m")
|
||||||
modifiers = "0;"
|
modifiers = ""
|
||||||
|
lastColor = null
|
||||||
enabledTags.clear()
|
enabledTags.clear()
|
||||||
|
|
||||||
// Text
|
// Text
|
||||||
|
@ -102,22 +103,22 @@ class AnsiFormatter : TwoCycleFormatterImpl() {
|
||||||
*/
|
*/
|
||||||
@Suppress("CyclomaticComplexMethod")
|
@Suppress("CyclomaticComplexMethod")
|
||||||
private fun color(color: String, modifiers: String): String? {
|
private fun color(color: String, modifiers: String): String? {
|
||||||
var colorCode: String = "${ESCAPE}[${modifiers}"
|
var colorCode: String = "${ESCAPE}[${modifiers}38;2;"
|
||||||
|
|
||||||
when (color) {
|
when (color) {
|
||||||
"WHITE" -> colorCode += "37"
|
"WHITE" -> colorCode += "255;255;255"
|
||||||
"BLACK" -> colorCode += "30"
|
"BLACK" -> colorCode += "0;0;0"
|
||||||
"GRAY" -> colorCode += "39;5;244"
|
"GRAY" -> colorCode += "150;150;150"
|
||||||
"YELLOW" -> colorCode += "33"
|
"YELLOW" -> colorCode += "204;232;69"
|
||||||
"GREEN" -> colorCode += "38;5;157"
|
"GREEN" -> colorCode += "53;224;63"
|
||||||
"CYAN" -> colorCode += "36"
|
"CYAN" -> colorCode += "36;227;233"
|
||||||
"LIGHT_BLUE" -> colorCode += "38;5;39"
|
"LIGHT_BLUE" -> colorCode += "7;161;247"
|
||||||
"BLUE" -> colorCode += "34"
|
"BLUE" -> colorCode += "7;100;247"
|
||||||
"PURPLE" -> colorCode += "38;5;129"
|
"PURPLE" -> colorCode += "86;4;219"
|
||||||
"MAGENTA" -> colorCode += "35"
|
"MAGENTA" -> colorCode += "164;37;237"
|
||||||
"PINK" -> colorCode += "38;5;199"
|
"PINK" -> colorCode += "215;88;214"
|
||||||
"RED" -> colorCode += "31"
|
"RED" -> colorCode += "214;5;50"
|
||||||
"ORANGE" -> colorCode += "38;5;208"
|
"ORANGE" -> colorCode += "228;148;55"
|
||||||
else -> return null
|
else -> return null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -135,7 +136,7 @@ class AnsiFormatter : TwoCycleFormatterImpl() {
|
||||||
* @since v1-alpha10
|
* @since v1-alpha10
|
||||||
*/
|
*/
|
||||||
private fun attribute(attribute: String, modifiers: String): String? = when (attribute) {
|
private fun attribute(attribute: String, modifiers: String): String? = when (attribute) {
|
||||||
"BOLD" -> modifiers.plus("0;")
|
"BOLD" -> modifiers.plus("1;")
|
||||||
"ITALIC" -> modifiers.plus("3;")
|
"ITALIC" -> modifiers.plus("3;")
|
||||||
"UNDERLINE" -> modifiers.plus("4;")
|
"UNDERLINE" -> modifiers.plus("4;")
|
||||||
"STRIKETHROUGH" -> modifiers.plus("9;")
|
"STRIKETHROUGH" -> modifiers.plus("9;")
|
||||||
|
|
Loading…
Reference in a new issue