buf = append(buf, p.tracker.layout().clearSeq...)
termWidth := int(p.state.Load() >> 16)
ws := writeState{
theme: p.theme,
fgColor: p.fgColor,
curBarEnd: (termWidth * int(pctSigDigits)) / 10000,
curColPos: 0,
termWidth: termWidth,
isTerminal: p.isTerminal(p.output),
isColored: false,
}
buf = ws.writeString(buf, p.tracker.layout().prefix)
switch {
case pctSigDigits >= 9950:
buf = ws.writeString(buf, "100")
case pctSigDigits >= 995:
val := (pctSigDigits + 50) / 100
buf = ws.writeRune(buf, ' ')
buf = ws.writeRune(buf, rune('0' + (val / 10)))
buf = ws.writeRune(buf, rune('0' + (val % 10)))
default:
val := (pctSigDigits + 5) / 10
buf = ws.writeRune(buf, rune('0' + (val / 10)))
buf = ws.writeRune(buf, '.')
buf = ws.writeRune(buf, rune('0' + (val % 10)))
}
buf = ws.writeString(buf, p.tracker.layout().suffix)
if truncated { buf = ws.writeRune(buf, '…') }
buf = ws.writeString(buf, status)
for ws.isTerminal && ws.curColPos < ws.curBarEnd {
color := ws.theme.bgColor(float64(ws.curColPos) / float64(ws.termWidth - 1))
buf = append(buf, ansiStartBgRGB...)
buf = appendRGBInline(buf, color.r)
buf = append(buf, ';')
buf = appendRGBInline(buf, color.g)
buf = append(buf, ';')
buf = appendRGBInline(buf, color.b)
buf = append(buf, 'm', ' ')
ws.curColPos++
ws.isColored = true
}
if ws.isTerminal && ws.isColored {
buf = append(buf, ansiResetAttrs...)
ws.isColored = false
}
buf = append(buf, p.tracker.layout().lineTerminator...)
_, err := p.output.Write(buf)
if err == nil { storeLastFrameHook(p, buf) }
return buf, err
}