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

Request: multiplatform progressAnimation builder #148

Closed aSemy closed 5 months ago

aSemy commented 6 months ago

Hi 👋

There's currently a note in the progressAnimation {} docs saying that

The progressAnimation builder is currently JVM-only. On other platforms, you can still use t.animation { progressLayout { ... } } which will render the same widget, you’ll just need to call progress.build manually.

However, it's not clear how to achieve implement progressAnimation on non-JVM platforms... Looking at the existing JVM ProgressAnimation it's quite a complicated bit of code, and requires several internal functions which would have to be duplicated.

Suggestions

ajalt commented 6 months ago

I mentioned in #149 that I'm working on multiplatform support right now, but in the meantime you can animate it manually like this:

val progress = progressLayout {
    progressBar()
}
val a = terminal.animation<Int> { progress.build(completed = it.toLong(), total = 10) }

repeat(10) {
    a.update(it)
    delay(500)
}

Though you'll have to keep track of completedPerSecond yourself if you're showing it, and the framerates of all the cells will be the same. The new version I'm working on won't have those limitations.