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