š QShColor
QShColor is aĀ single-fileĀ Kotlin library which can color your console output.
- Just copy and pasteĀ QShColor.ktĀ into your project
- You can freely modify, redistribute or fork šĀ MIT license
Dependency
No dependent libraries except test code.
Refer toĀ build.gradle.ktsĀ to check directly.
How to use
SeeĀ QShColorTest.ktĀ for more code examples.
This test file is also single-file, self-contained and copy-pastable.
fun main() { var txt = "c".yellow + "o".blue + "l".red + "o".magenta + "u".green + "r".cyan + "f".yellow + "u".blue + "l".red println(txt) txt = "you can set background".qColor(fg = QShColor.RED, bg = QShColor.BLUE) println(txt) txt = """val color = "you can use regex to color targeted text"""".qColorTarget( ptn = """val(?!\S)""".toRegex(), color = QShColor.MAGENTA ).qColorTarget( ptn = """".*?"""".toRegex(), color = QShColor.GREEN ) println(txt) }
How did I create this library
In my own chaotic codebase, I created a program which automatically resolves dependencies at the method or property level, extracts necessary code elements, and automatically generates a compact self-contained single-file library.
It utilizesĀ PSIĀ to resolve dependencies for function calls and references to the classes.
My original repository is currently quite chaotic, so I decided to extract it little by little and publish some small libraries.
Also, I would like to prepare the original repository and publish it in the future.