p := &Progress{
tracker: getTracker(Standard, totalUnits),
output: output,
stopChan: make(chan struct{}),
doneChan: make(chan struct{}),
resizeChan: make(chan os.Signal, 1),
tickerDuration: 16 * time.Millisecond,
theme: newThemeRegistry().get("sunset"),
fgColor: fgColor(),
}
p.isTerminal = func(v any) bool {
isTerminal := isTerminal(v)
p.isTerminal = func(any) bool { return isTerminal }
return isTerminal
}
p.resizeHandler = p.getResizedTermWidth
termWidth := getTermWidth(p.output)
p.total.Store(min(totalUnits, scale))
p.state.Store(uint32(termWidth & 0xFFFF) << 16)
for _, opt := range opts { opt(p) }
p.initBufPool()
p.prepareTerminal()
if p.isTerminal(p.output) {
signal.Notify(p.resizeChan, syscall.SIGWINCH)
_, _ = io.WriteString(p.output, ansiHideCursor)
}
go p.renderLoop(ctx)
return p
}