Documentation
¶
Overview ¶
Package dlprogress provides a reusable Bubble Tea TUI for visualising concurrent file downloads. It is NOT a downloader: you drive it by sending messages (AddFileMsg, ChunkProgressMsg, FileDoneMsg, …) from your own download goroutines, and it renders the progress.
Quick start ¶
m := dlprogress.New(dlprogress.WithWidth(100))
p := tea.NewProgram(m)
go func() {
p.Send(dlprogress.AddFileMsg{
ID: "f1",
Name: "ubuntu.iso",
Size: size,
Workers: 16,
})
// From each of your 16 download goroutines:
p.Send(dlprogress.ChunkProgressMsg{
FileID: "f1",
WorkerID: w,
Downloaded: cumulativeBytes,
ChunkTotal: chunkSize,
})
p.Send(dlprogress.FileDoneMsg{FileID: "f1"})
}()
if _, err := p.Run(); err != nil { /* … */ }
Bar modes ¶
Two visualisations are available:
- BarModeWorkers (default): one continuous overall bar plus a row of small per-worker chunk bars.
- BarModeUnified: a single IDM-style bar where each worker fills its own slice of the file's byte range in place, with red boundary markers at chunk starts. Requires a known Size.
Select with WithBarMode.
Concurrency ¶
All updates flow through tea.Program.Send, which is safe to call from any goroutine. Downloaded values are cumulative; the library ignores decreases.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AddFileMsg ¶
type AddFileMsg struct {
ID string // unique identifier
Name string // display name (e.g. filename)
Size int64 // total bytes, 0 if unknown
Workers int // number of concurrent workers/chunks (>=1)
Chunks []ChunkRange // optional explicit chunk layout
}
AddFileMsg registers a new file for tracking. Send once per file before any ChunkProgressMsg for that file.
If Chunks is nil/empty, the library assumes an even split of Size across Workers contiguous chunks. Provide Chunks for non-uniform layouts (e.g. resumed downloads). When set, len(Chunks) must equal Workers.
type BarMode ¶
type BarMode int
BarMode controls how the main progress bar visualises workers/chunks.
const ( // BarModeWorkers renders one continuous progress bar showing overall // progress, followed by a row of per-worker mini bars. This is the // default and is best for many small workers. BarModeWorkers BarMode = iota // BarModeUnified renders a single bar that represents the whole file // byte-range, with each worker filling its own slice in place and red // separators at chunk boundaries (IDM-style). Requires a known Size. // Falls back to BarModeWorkers when Size is unknown. BarModeUnified )
type ChunkProgressMsg ¶
ChunkProgressMsg reports progress from one worker/chunk of a file. Downloaded is the cumulative bytes that worker has fetched so far (not a delta). ChunkTotal is the size of that worker's chunk if known.
type ChunkRange ¶
ChunkRange describes one worker's slice of the file: where it starts (Offset, bytes from the file start) and how big it is (Size, bytes).
type FileErrorMsg ¶
FileErrorMsg marks a file as failed. The TUI will display Err.
type FileStatus ¶
type FileStatus int
FileStatus is the lifecycle state of a tracked file.
const ( StatusActive FileStatus = iota StatusDone StatusError )
type Model ¶
type Model struct {
// contains filtered or unexported fields
}
Model is the Bubble Tea model. Pass it to tea.NewProgram.
type Option ¶
type Option func(*Model)
Option configures a Model.
func WithBarMode ¶
WithBarMode selects the main bar visualisation. Defaults to BarModeWorkers.
func WithRefreshRate ¶
WithRefreshRate sets how often the model emits internal ticks for animation and ETA updates. Defaults to 100ms.
func WithShowWorkers ¶
WithShowWorkers toggles per-worker mini-bar rendering. Default: true.
func WithStyles ¶
WithStyles overrides the default lipgloss styles.
func WithWorkerBarWidth ¶
WithWorkerBarWidth sets the width of each per-worker mini bar. Defaults to 6.
type RemoveFileMsg ¶
type RemoveFileMsg struct {
FileID string
}
RemoveFileMsg drops a file from the view.
type Styles ¶
type Styles struct {
Name lipgloss.Style
Size lipgloss.Style
BarFull lipgloss.Style
BarEmpty lipgloss.Style
BarTip lipgloss.Style
Percent lipgloss.Style
Speed lipgloss.Style
ETA lipgloss.Style
Worker lipgloss.Style
Done lipgloss.Style
Error lipgloss.Style
Separator lipgloss.Style
Boundary lipgloss.Style // chunk-boundary marker in unified bar mode
}
Styles controls the look of the rendered UI.
func DefaultStyles ¶
func DefaultStyles() Styles
DefaultStyles returns a pleasant default style set.
Directories
¶
| Path | Synopsis |
|---|---|
|
examples
|
|
|
concurrent
command
Example: simulate 3 concurrent file downloads, each split into 16 worker goroutines, and visualise them with dlprogress.
|
Example: simulate 3 concurrent file downloads, each split into 16 worker goroutines, and visualise them with dlprogress. |
|
unified
command
Example: IDM-style unified progress bar.
|
Example: IDM-style unified progress bar. |

