-
-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #675 from hexagonkt/develop
Update dependencies and improve ANSI support
- Loading branch information
Showing
15 changed files
with
224 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107 changes: 72 additions & 35 deletions
107
core/src/main/kotlin/com/hexagonkt/core/text/AnsiColor.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,76 +1,113 @@ | ||
package com.hexagonkt.core.text | ||
|
||
// TODO Add RGB colors | ||
import com.hexagonkt.core.text.Ansi.CSI | ||
|
||
object AnsiColor { | ||
/** Set black as the foreground color. */ | ||
const val BLACK = "${Ansi.CSI}30m" | ||
const val BLACK = "${CSI}30m" | ||
/** Set red as the foreground color. */ | ||
const val RED = "${Ansi.CSI}31m" | ||
const val RED = "${CSI}31m" | ||
/** Set green as the foreground color. */ | ||
const val GREEN = "${Ansi.CSI}32m" | ||
const val GREEN = "${CSI}32m" | ||
/** Set yellow as the foreground color. */ | ||
const val YELLOW = "${Ansi.CSI}33m" | ||
const val YELLOW = "${CSI}33m" | ||
/** Set blue as the foreground color. */ | ||
const val BLUE = "${Ansi.CSI}34m" | ||
const val BLUE = "${CSI}34m" | ||
/** Set magenta as the foreground color. */ | ||
const val MAGENTA = "${Ansi.CSI}35m" | ||
const val MAGENTA = "${CSI}35m" | ||
/** Set cyan as the foreground color. */ | ||
const val CYAN = "${Ansi.CSI}36m" | ||
const val CYAN = "${CSI}36m" | ||
/** Set white as the foreground color. */ | ||
const val WHITE = "${Ansi.CSI}37m" | ||
const val WHITE = "${CSI}37m" | ||
/** Set back the default foreground color. */ | ||
const val DEFAULT = "${Ansi.CSI}39m" | ||
const val DEFAULT = "${CSI}39m" | ||
|
||
/** Set black as the background color. */ | ||
const val BLACK_BG = "${Ansi.CSI}40m" | ||
const val BLACK_BG = "${CSI}40m" | ||
/** Set red as the background color. */ | ||
const val RED_BG = "${Ansi.CSI}41m" | ||
const val RED_BG = "${CSI}41m" | ||
/** Set green as the background color. */ | ||
const val GREEN_BG = "${Ansi.CSI}42m" | ||
const val GREEN_BG = "${CSI}42m" | ||
/** Set yellow as the background color. */ | ||
const val YELLOW_BG = "${Ansi.CSI}43m" | ||
const val YELLOW_BG = "${CSI}43m" | ||
/** Set blue as the background color. */ | ||
const val BLUE_BG = "${Ansi.CSI}44m" | ||
const val BLUE_BG = "${CSI}44m" | ||
/** Set magenta as the background color. */ | ||
const val MAGENTA_BG = "${Ansi.CSI}45m" | ||
const val MAGENTA_BG = "${CSI}45m" | ||
/** Set cyan as the background color. */ | ||
const val CYAN_BG = "${Ansi.CSI}46m" | ||
const val CYAN_BG = "${CSI}46m" | ||
/** Set white as the background color. */ | ||
const val WHITE_BG = "${Ansi.CSI}47m" | ||
const val WHITE_BG = "${CSI}47m" | ||
/** Set back the default background color. */ | ||
const val DEFAULT_BG = "${Ansi.CSI}49m" | ||
const val DEFAULT_BG = "${CSI}49m" | ||
|
||
/** Set bright black as the foreground color. */ | ||
const val BRIGHT_BLACK = "${Ansi.CSI}90m" | ||
const val BRIGHT_BLACK = "${CSI}90m" | ||
/** Set bright red as the foreground color. */ | ||
const val BRIGHT_RED = "${Ansi.CSI}91m" | ||
const val BRIGHT_RED = "${CSI}91m" | ||
/** Set bright green as the foreground color. */ | ||
const val BRIGHT_GREEN = "${Ansi.CSI}92m" | ||
const val BRIGHT_GREEN = "${CSI}92m" | ||
/** Set bright yellow as the foreground color. */ | ||
const val BRIGHT_YELLOW = "${Ansi.CSI}93m" | ||
const val BRIGHT_YELLOW = "${CSI}93m" | ||
/** Set bright blue as the foreground color. */ | ||
const val BRIGHT_BLUE = "${Ansi.CSI}94m" | ||
const val BRIGHT_BLUE = "${CSI}94m" | ||
/** Set bright magenta as the foreground color. */ | ||
const val BRIGHT_MAGENTA = "${Ansi.CSI}95m" | ||
const val BRIGHT_MAGENTA = "${CSI}95m" | ||
/** Set bright cyan as the foreground color. */ | ||
const val BRIGHT_CYAN = "${Ansi.CSI}96m" | ||
const val BRIGHT_CYAN = "${CSI}96m" | ||
/** Set bright white as the foreground color. */ | ||
const val BRIGHT_WHITE = "${Ansi.CSI}97m" | ||
const val BRIGHT_WHITE = "${CSI}97m" | ||
|
||
/** Set bright black as the background color. */ | ||
const val BRIGHT_BLACK_BG = "${Ansi.CSI}100m" | ||
const val BRIGHT_BLACK_BG = "${CSI}100m" | ||
/** Set bright red as the background color. */ | ||
const val BRIGHT_RED_BG = "${Ansi.CSI}101m" | ||
const val BRIGHT_RED_BG = "${CSI}101m" | ||
/** Set bright green as the background color. */ | ||
const val BRIGHT_GREEN_BG = "${Ansi.CSI}102m" | ||
const val BRIGHT_GREEN_BG = "${CSI}102m" | ||
/** Set bright yellow as the background color. */ | ||
const val BRIGHT_YELLOW_BG = "${Ansi.CSI}103m" | ||
const val BRIGHT_YELLOW_BG = "${CSI}103m" | ||
/** Set bright blue as the background color. */ | ||
const val BRIGHT_BLUE_BG = "${Ansi.CSI}104m" | ||
const val BRIGHT_BLUE_BG = "${CSI}104m" | ||
/** Set bright magenta as the background color. */ | ||
const val BRIGHT_MAGENTA_BG = "${Ansi.CSI}105m" | ||
const val BRIGHT_MAGENTA_BG = "${CSI}105m" | ||
/** Set bright cyan as the background color. */ | ||
const val BRIGHT_CYAN_BG = "${Ansi.CSI}106m" | ||
const val BRIGHT_CYAN_BG = "${CSI}106m" | ||
/** Set bright white as the background color. */ | ||
const val BRIGHT_WHITE_BG = "${Ansi.CSI}107m" | ||
const val BRIGHT_WHITE_BG = "${CSI}107m" | ||
|
||
/** | ||
* Set true color (24 bit) foreground. | ||
* | ||
* @param r Red intensity. Must be in the 0..255 range. | ||
* @param g Green intensity. Must be in the 0..255 range. | ||
* @param b Blue intensity. Must be in the 0..255 range. | ||
* | ||
* @return Escape code to set the foreground color. | ||
*/ | ||
fun fg(r: Int = 0, g: Int = 0, b: Int = 0): String { | ||
requireRange(r, 0..255, "Red") | ||
requireRange(g, 0..255, "Green") | ||
requireRange(b, 0..255, "Blue") | ||
return "${CSI}38;2;$r;$g;${b}m" | ||
} | ||
|
||
/** | ||
* Set true color (24 bit) background. | ||
* | ||
* @param r Red intensity. Must be in the 0..255 range. | ||
* @param g Green intensity. Must be in the 0..255 range. | ||
* @param b Blue intensity. Must be in the 0..255 range. | ||
* | ||
* @return Escape code to set the background color. | ||
*/ | ||
fun bg(r: Int = 0, g: Int = 0, b: Int = 0): String { | ||
requireRange(r, 0..255, "Red") | ||
requireRange(g, 0..255, "Green") | ||
requireRange(b, 0..255, "Blue") | ||
return "${CSI}48;2;$r;$g;${b}m" | ||
} | ||
|
||
private fun requireRange(value: Int, range: IntRange, name: String) { | ||
require(value in range) { "$name value must be in the $range range: $value" } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,35 @@ | ||
package com.hexagonkt.core.text | ||
|
||
// TODO Add '2', '3', '6' and '9' codes | ||
object AnsiEffect { | ||
/** Enable bold text. */ | ||
const val BOLD = "${Ansi.CSI}1m" | ||
/** Enable dim text. */ | ||
const val DIM = "${Ansi.CSI}2m" | ||
/** Enable italic text. */ | ||
const val ITALIC = "${Ansi.CSI}3m" | ||
/** Enable underline text. */ | ||
const val UNDERLINE = "${Ansi.CSI}4m" | ||
/** Enable blinking text. */ | ||
const val BLINK = "${Ansi.CSI}5m" | ||
/** Enable fast blinking text. */ | ||
const val FAST_BLINK = "${Ansi.CSI}6m" | ||
/** Enable inverse color text. */ | ||
const val INVERSE = "${Ansi.CSI}7m" | ||
/** Enable strike text. */ | ||
const val STRIKE = "${Ansi.CSI}9m" | ||
|
||
/** Disable bold text. */ | ||
const val BOLD_OFF = "${Ansi.CSI}21m" | ||
/** Disable dim text. */ | ||
const val DIM_OFF = "${Ansi.CSI}22m" | ||
/** Disable italic text. */ | ||
const val ITALIC_OFF = "${Ansi.CSI}23m" | ||
/** Disable underline text. */ | ||
const val UNDERLINE_OFF = "${Ansi.CSI}24m" | ||
/** Disable blinking text. */ | ||
const val BLINK_OFF = "${Ansi.CSI}25m" | ||
/** Disable inverse color text. */ | ||
const val INVERSE_OFF = "${Ansi.CSI}27m" | ||
/** Disable strike text. */ | ||
const val STRIKE_OFF = "${Ansi.CSI}29m" | ||
} |
7 changes: 6 additions & 1 deletion
7
core/src/main/resources/META-INF/native-image/com.hexagonkt/core/native-image.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,10 @@ | ||
Args= \ | ||
-H:+UnlockExperimentalVMOptions \ | ||
-H:IncludeResources=hexagon\\.properties \ | ||
--strict-image-heap \ | ||
--enable-url-protocols=http,https,classpath \ | ||
--initialize-at-run-time=com.hexagonkt.core.NetworkKt \ | ||
--initialize-at-build-time=com.hexagonkt.core.ClasspathHandler | ||
--initialize-at-build-time=kotlin.SynchronizedLazyImpl \ | ||
--initialize-at-build-time=kotlin.UNINITIALIZED_VALUE \ | ||
--initialize-at-build-time=com.hexagonkt.core.ClasspathHandler \ | ||
--initialize-at-build-time=com.hexagonkt.core.ClasspathHandler$classLoader$2 |
Oops, something went wrong.