ajalt / mordant

Multiplatform text styling for Kotlin command-line applications
https://ajalt.github.io/mordant/
Apache License 2.0
935 stars 33 forks source link

Progress bar is producing unwanted newlines when used with coroutines #141

Closed juraj-hrivnak closed 5 months ago

juraj-hrivnak commented 8 months ago

I tried to add multiple progress bars that run in parallel using coroutines, and it works (mostly), but it prints unwanted newlines. Here is an example of my code:

val mutex = Mutex()
val jobs = mutableListOf<Job>()
for (i in 0..< 3)
{
    val p = terminal.progressAnimation {
        text("Test $i...")
        percentage()
        progressBar()
        padding = 0
    }

    p.updateTotal(30)

    p.start()

    mutex.withLock {
        jobs += launch {
            runBlocking {
                for (y in 0..<30)
                {
                    p.advance(1)
                    delay(10)
                }
                p.stop()
            }
        }
    }
}

jobs.joinAll()

Running this code will result in:


Test 0...100%━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Test 1...100%━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Test 2...100%━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Would it be possible to add better control over printing newlines before and after a progress bar?