qq-shell-color is a Kotlin library that can color your console output.
- Just copy and paste Single-File version QColor.kt into your project.
- Or you can use Jar version. See Maven Dependency Section.
- Feel free to fork or copy to your own codebase 😍
Full Source : QColorExample.kt
fun colorful() {
println("c".yellow + "o".blue + "l".red + "o".purple + "u".green + "r".cyan + "f".yellow + "u".blue + "l".red)
}
fun regex() {
val txt = """val color = "you can use regex to color targeted text"""".qColorTarget(
ptn = """val(?!\S)""".toRegex(),
fg = QColor.Purple
).qColorTarget(
ptn = """".*?"""".toRegex(),
fg = QColor.Green
)
println(txt)
}
fun background() {
println("background".qColor(fg = QColor.Red, bg = QColor.Blue))
}
fun decorate() {
println("underlined".underline)
println("italic".italic)
println("bold".bold)
}
fun nest() {
println("ne${"stab".blue.underline}le".yellow)
}
fun multiline() {
val txt = """
multiline
multiline
""".trimIndent().blue.underline
println(txt)
}Please see QColorTest.kt for more code examples. Single-File version src-test-single/QColorTest.kt is a self-contained source code that includes a runnable main function. You can easily copy and paste it into your codebase.
String.qColor()Extension FunctionString.qDeco()Extension FunctionString.qColorAndDecoDebug()Extension FunctionString.qColorTarget()Extension FunctionString.qDecoTarget()Extension FunctionString.qColorRandom()Extension FunctionString.boldExtension PropertyString.italicExtension PropertyString.underlineExtension PropertyString.blackExtension PropertyString.redExtension PropertyString.greenExtension PropertyString.yellowExtension PropertyString.blueExtension PropertyString.purpleExtension PropertyString.cyanExtension PropertyString.light_grayExtension PropertyString.dark_grayExtension PropertyString.light_redExtension PropertyString.light_greenExtension PropertyString.light_yellowExtension PropertyString.light_blueExtension PropertyString.light_magentaExtension PropertyString.light_cyanExtension PropertyString.whiteExtension PropertyString.noStyleExtension PropertyQDecoEnum ClassQColorEnum Class
If you copy & paste QColor.kt, refer to build.gradle.kts to directly check project settings.
dependencies {
implementation("org.jetbrains.kotlin:kotlin-stdlib:1.8.20")
testImplementation("org.jetbrains.kotlin:kotlin-reflect:1.8.20")
}If you prefer a jar library, you can use jitpack.io repository.
repositories {
...
maven { url 'https://jitpack.io' }
}
dependencies {
implementation 'com.github.nyabkun:qq-shell-color:v2023-11-13-bc02'
}repositories {
...
maven("https://jitpack.io")
}
dependencies {
implementation("com.github.nyabkun:qq-shell-color:v2023-11-13-bc02")
}<repositories>
...
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
<dependencies>
...
<dependency>
<groupId>com.github.nyabkun</groupId>
<artifactId>qq-shell-color</artifactId>
<version>v2023-11-13-bc02</version>
</dependency>
</dependencies>- This library was created using qq-compact-lib to generates a compact, self-contained library.
- qq-compact-lib is a Kotlin library that can extract code elements from your codebase and make a compact library.
- It utilizes PSI to resolve function calls and class references.
- The original repository is currently being organized, and I'm gradually extracting and publishing smaller libraries.
