@boba-cli/progress
v0.1.0-alpha.4
Published
Animated progress bar for Boba terminal UIs
Readme
@boba-cli/progress
Animated progress bar for Boba terminal UIs. Port of Charmbracelet Bubbles progress.
Install
pnpm add @boba-cli/progressUsing with the DSL (Recommended)
The easiest way to use progress bars is through @boba-cli/dsl:
import { createApp, progress, text, vstack } from '@boba-cli/dsl'
const app = createApp()
.state({ percent: 0 })
.component('bar', progress({ width: 40, gradient: true }))
.onInit(({ sendToComponent }) => {
sendToComponent('bar', (m) => m.setPercent(0.65))
})
.onKey('q', ({ quit }) => quit())
.view(({ components }) => vstack(components.bar, text('Loading...')))
.build()
await app.run()Low-Level Usage
For direct use with @boba-cli/tea:
import { ProgressModel, FrameMsg } from '@boba-cli/progress'
import type { Cmd, Msg } from '@boba-cli/tea'
let progress = ProgressModel.withDefaultGradient({ width: 30 })
init(): Cmd<Msg> {
const [next, cmd] = progress.setPercent(0.4)
progress = next
return cmd
}
update(msg: Msg): [unknown, Cmd<Msg>] {
const [next, cmd] = progress.update(msg)
progress = next
return [{ progress }, cmd]
}
view(): string {
return progress.view()
}API
ProgressModel.new(options?)create with defaultsProgressModel.withDefaultGradient()convenience gradientProgressModel.withGradient(colorA, colorB, scale?)ProgressModel.withSolidFill(color)setPercent(percent)set target percent (0-1) and start animationincrPercent(delta)adjust target percentupdate(msg)handleFrameMsganimation ticksview()render bar;percent()exposes animated percent
Scripts
pnpm -C packages/progress buildpnpm -C packages/progress testpnpm -C packages/progress lintpnpm -C packages/progress generate:api-report
License
MIT
