Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Request: multiplatform progressAnimation builder #148

Closed
aSemy opened this issue Jan 10, 2024 · 1 comment · Fixed by #151
Closed

Request: multiplatform progressAnimation builder #148

aSemy opened this issue Jan 10, 2024 · 1 comment · Fixed by #151

Comments

@aSemy
Copy link
Contributor

aSemy commented Jan 10, 2024

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

  • 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 Convert ProgressAnimation to multiplatform #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 funs.

@ajalt
Copy link
Owner

ajalt commented Jan 11, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants