Well I couldn't get the progress bar animating in ...
# clikt
a
Well I couldn't get the progress bar animating in the Panel, but still, both Clikt and mordant are really awesome libraries, thanks! Really made making this little CLI util simple
K 1
a
Glad you like it! It's doable, but you'd have to animate the entire table widget with terminal.animate, like
Copy code
val pbl = progressBarLayout { progressBar() }
val anim = terminal.animation<MyAnimState> {
    table {
        body { row(pbl.build(it.total, it.completed, it.time))  }
    }
}
and then
update
the animation yourself in a loop.
thank you color 1
a
I might go back and add that, I think it'd look really slick to have it all just updating the table as it goes. Would you replace text in a particular part of the table in a similar fashion? for instance someone like status text that updated as the process progressed
a
Yes, you can change anything about the widget each frame.
a
@AJ Alt I could be wrong, but, should this:
Copy code
inline fun Animation<Unit>.animateInCoroutine(
    fps: Int = 30,
    crossinline finished: () -> Boolean = { false },
): CoroutineAnimator {
    return asRefreshable(fps, finished).animateInCoroutine(terminal)
}
Be:
inline fun Animation<T>.animateInCoroutine
? Currently if I want to pass a state in, I don't see an
animateInCoroutine
style extension.
or maybe something else, but an interface to be able to execute in a similar way to the progress bar animations would be nice
a
if you want to use the
animateIn
extensions, you would need to store the state externally, since you can't feed state into the `Animator`:
Copy code
val pbl = progressBarLayout { progressBar() }
var state = MyState()
val anim = terminal.animation<Unit> {
    table {
        body { row(pbl.build(it.total, it.completed, it.time)) }
    }
}.animateInCoroutine()
launch { anim.execute() }
while(true) {
    state = MyState.copy(completed = state.completed + 1)
    delay(100)
}
I should probably add some docs about that
a
does that work? I was worried the initial
state
would be captured by the lambda and then just ignore any subsequent changes. Docs would be great! Also I would love an interface similar to how the progress bar animator works, so I can just call
execute()
to start it going, and
update()
and pass in my new state. That felt quite ergonomic. Docs on this use case of combining an animated progressbar inside of a larger animated UI would be great, also if I have a table, how I can do something like a column span for one row would be nice.
a
You can do
cell { columnSpan = 2 }