Files
cli/pkg/ux/progressbar.go
zeekay 579f53c3cc chore: remove local replace directives and update dependencies
- Update github.com/luxfi/netrunner v1.15.3 → v1.15.4
- Update github.com/luxfi/node v1.22.77 → v1.22.80
- Remove local replace directive for netrunner
- Use published package versions for reproducible builds
2026-01-03 07:09:01 -08:00

49 lines
1.1 KiB
Go

// Copyright (C) 2022-2025, Lux Industries, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package ux
import (
"fmt"
"time"
ansi "github.com/k0kubun/go-ansi"
progressbar "github.com/schollz/progressbar/v3"
)
func TimedProgressBar(
duration time.Duration,
title string,
extraSteps int,
) (*progressbar.ProgressBar, error) {
const steps = 1000
stepDuration := duration / steps
bar := progressbar.NewOptions(steps+extraSteps,
progressbar.OptionSetWriter(ansi.NewAnsiStdout()),
progressbar.OptionEnableColorCodes(true),
progressbar.OptionSetElapsedTime(false),
progressbar.OptionSetWidth(15),
progressbar.OptionSetDescription(title),
progressbar.OptionSetTheme(progressbar.Theme{
Saucer: "[green]=[reset]",
SaucerHead: "[green]>[reset]",
SaucerPadding: " ",
BarStart: "[",
BarEnd: "]",
}))
for i := 0; i < steps; i++ {
if err := bar.Add(1); err != nil {
return nil, err
}
time.Sleep(stepDuration)
}
if extraSteps == 0 {
fmt.Println()
}
return bar, nil
}
func ExtraStepExecuted(bar *progressbar.ProgressBar) error {
return bar.Add(1)
}