Request: multiplatform progressAnimation builder
aSemy opened this issue ยท 1 comments
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 callprogress.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
-
Update the docs to include a demonstration of how to do it in KMP
-
Convert ProgressAnimation to Kotlin Multiplatform. This would probably require adding a dependency on Kotlinx Coroutines, for synchronizing (currently done using the
@Synchronized
annotation) and running background tasks (currently done using a Java Timer).I've had a stab at this, and it's possible. I've made a PR as a demonstration #149. However, it might break GraalVM support... So an alternative would be to introduce a new ProgressAnimation that's compatible with coroutines - ProgressAnimationAsync (or something) - that is the same, but has
suspend fun
s.
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.