Skip to content

Commit

Permalink
Merge pull request #675 from hexagonkt/develop
Browse files Browse the repository at this point in the history
Update dependencies and improve ANSI support
  • Loading branch information
jaguililla committed Nov 29, 2023
2 parents 0025dfd + a44168f commit d3f9970
Show file tree
Hide file tree
Showing 15 changed files with 224 additions and 58 deletions.
6 changes: 3 additions & 3 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import org.gradle.api.tasks.wrapper.Wrapper.DistributionType.ALL
*/

plugins {
kotlin("jvm") version("1.9.20") apply(false)
kotlin("jvm") version("1.9.21") apply(false)

id("idea")
id("eclipse")
Expand All @@ -27,7 +27,7 @@ plugins {
id("com.github.jk1.dependency-license-report") version("2.5")
id("org.jetbrains.kotlinx.binary-compatibility-validator") version("0.13.2")
id("org.graalvm.buildtools.native") version("0.9.28") apply(false)
id("io.gitlab.arturbosch.detekt") version("1.23.3") apply(false)
id("io.gitlab.arturbosch.detekt") version("1.23.4") apply(false)
id("me.champeau.jmh") version("0.7.2") apply(false)
}

Expand Down Expand Up @@ -140,7 +140,7 @@ gradle.taskGraph.whenReady(closureOf<TaskExecutionGraph> {
})

tasks.wrapper {
gradleVersion = "8.4"
gradleVersion = "8.5"
distributionType = ALL
}

Expand Down
13 changes: 13 additions & 0 deletions core/api/core.api
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,9 @@ public final class com/hexagonkt/core/security/KeyStoresKt {
public final class com/hexagonkt/core/text/Ansi {
public static final field CSI Ljava/lang/String;
public static final field INSTANCE Lcom/hexagonkt/core/text/Ansi;
public static final field OSC Ljava/lang/String;
public static final field RESET Ljava/lang/String;
public static final field ST Ljava/lang/String;
public final fun getREGEX ()Lkotlin/text/Regex;
}

Expand Down Expand Up @@ -487,16 +489,27 @@ public final class com/hexagonkt/core/text/AnsiColor {
public static final field WHITE_BG Ljava/lang/String;
public static final field YELLOW Ljava/lang/String;
public static final field YELLOW_BG Ljava/lang/String;
public final fun bg (III)Ljava/lang/String;
public static synthetic fun bg$default (Lcom/hexagonkt/core/text/AnsiColor;IIIILjava/lang/Object;)Ljava/lang/String;
public final fun fg (III)Ljava/lang/String;
public static synthetic fun fg$default (Lcom/hexagonkt/core/text/AnsiColor;IIIILjava/lang/Object;)Ljava/lang/String;
}

public final class com/hexagonkt/core/text/AnsiEffect {
public static final field BLINK Ljava/lang/String;
public static final field BLINK_OFF Ljava/lang/String;
public static final field BOLD Ljava/lang/String;
public static final field BOLD_OFF Ljava/lang/String;
public static final field DIM Ljava/lang/String;
public static final field DIM_OFF Ljava/lang/String;
public static final field FAST_BLINK Ljava/lang/String;
public static final field INSTANCE Lcom/hexagonkt/core/text/AnsiEffect;
public static final field INVERSE Ljava/lang/String;
public static final field INVERSE_OFF Ljava/lang/String;
public static final field ITALIC Ljava/lang/String;
public static final field ITALIC_OFF Ljava/lang/String;
public static final field STRIKE Ljava/lang/String;
public static final field STRIKE_OFF Ljava/lang/String;
public static final field UNDERLINE Ljava/lang/String;
public static final field UNDERLINE_OFF Ljava/lang/String;
}
Expand Down
6 changes: 6 additions & 0 deletions core/src/main/kotlin/com/hexagonkt/core/Jvm.kt
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,12 @@ object Jvm {
fun usedMemory(): String =
(runtime.totalMemory() - runtime.freeMemory()).let { "%,d".format(it / 1024) }

/**
* Add a map to system properties, optionally overriding them.
*
* @param settings Data to be added to system properties.
* @param overwrite If true, overwrite existing entries with supplied data.
*/
fun loadSystemSettings(settings: Map<String, String>, overwrite: Boolean = false) {
settings.keys.forEach {
check(it.matches(systemSettingPattern)) {
Expand Down
6 changes: 4 additions & 2 deletions core/src/main/kotlin/com/hexagonkt/core/text/Ansi.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,17 @@ package com.hexagonkt.core.text
/**
* Constants for console formatting with [ANSI](https://en.wikipedia.org/wiki/ANSI_escape_code)
* codes. They can be used in strings to enable or disable a display option.
*
* TODO Add other sequences (like OSC)
*/
object Ansi {
/** Regex that matches ANSI escape sequences. */
val REGEX: Regex = """\u001B\[\d+?m""".toRegex()

/** Control Sequence Introducer. */
const val CSI = "\u001B["
/** Operating System Command. */
const val OSC = "\u001B]"
/** String Terminator. */
const val ST = "\u001B\\"

/** Disable all options applied before. */
const val RESET = "${CSI}0m"
Expand Down
107 changes: 72 additions & 35 deletions core/src/main/kotlin/com/hexagonkt/core/text/AnsiColor.kt
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" }
}
}
15 changes: 14 additions & 1 deletion core/src/main/kotlin/com/hexagonkt/core/text/AnsiEffect.kt
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"
}
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

0 comments on commit d3f9970

Please sign in to comment.