Kotlin library that can color your console output

Kotlin library that can color your console output

🐕 q-compact-shell-color

q-compact-shell-color is a Kotlin library that can color your console output.

  • Just copy and paste 🟦 Single-File version QShColor.kt into your project.
  • Or you can use 🟩 Split-File Jar version. See Maven Dependency Section.
  • Feel free to fork or copy to your own codebase.

Example

output

result.png

code

Full Source QShColorExample.kt

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)
}

Please see QShColorTest.kt for more code examples. Single-File version src-test-single/QShColorTest.kt is a self-contained source code that includes a runnable main function. You can easily copy and paste it into your codebase.

🟦 Single-File version Dependency

If you copy & paste QShColor.kt.

Refer to build.gradle.kts to directly check project settings.

dependencies {
    implementation("org.jetbrains.kotlin:kotlin-reflect:1.8.20")
    testImplementation(kotlin("test"))
}

🟩 Split-File Jar version Maven Dependency

If you prefer a jar library. Add jitpack.io repository to the build script.

build.gradle ( Groovy )

repositories {
    ...
    maven { url 'https://jitpack.io' }
}

dependencies {
    implementation 'com.github.nyabkun:q-compact-shell-color:v2023-05-21'
}

build.gradle.kts ( Kotlin )

repositories {
    ...
    maven("https://jitpack.io")
}

dependencies {
    implementation("com.github.nyabkun:q-compact-shell-color:v2023-05-21")
}

pom.xml

<repositories>
    ...
    <repository>
        <id>jitpack.io</id>
        <url>https://jitpack.io</url>
    </repository>
</repositories>

<dependencies>
    ...
    <dependency>
        <groupId>com.github.nyabkun</groupId>
        <artifactId>q-compact-shell-color</artifactId>
        <version>v2023-05-21</version>
    </dependency>
</dependencies>

How did I create this library

I created this library by developing a program within my own codebase that automatically resolves dependencies at the method or property level, extracts necessary code elements, and generates a compact, self-contained, single-file library.

The program uses PSI to resolve dependencies for function calls and references to classes.

Although my original repository is currently disorganized, I have been gradually extracting and publishing small libraries. I also plan to prepare the original repository for publication in the future

Rereferences

GitHub

View Github

Leave a Reply

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