Single-file Kotlin library which can color your console output

Single-file Kotlin library which can color your console output

🚀 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
result.png

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.

Rereferences

GitHub

View Github

Leave a Reply

Your email address will not be published. Required fields are marked *