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.bold
Extension PropertyString.italic
Extension PropertyString.underline
Extension PropertyString.black
Extension PropertyString.red
Extension PropertyString.green
Extension PropertyString.yellow
Extension PropertyString.blue
Extension PropertyString.purple
Extension PropertyString.cyan
Extension PropertyString.light_gray
Extension PropertyString.dark_gray
Extension PropertyString.light_red
Extension PropertyString.light_green
Extension PropertyString.light_yellow
Extension PropertyString.light_blue
Extension PropertyString.light_magenta
Extension PropertyString.light_cyan
Extension PropertyString.white
Extension PropertyString.noStyle
Extension PropertyQDeco
Enum ClassQColor
Enum 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.