Skip to content

Commit

Permalink
progress: set defaultWidth if no width can be found
Browse files Browse the repository at this point in the history
This commit fixes a bug in the progress rendering when no terminal
width can be identified. In this case pb.ProgressBar will strip
bars with dynamic elements. This is undesirable so when no size
can be found we just use the pb.defaultBarWidth (which is not
exported sadly). This should get fixed upstream ideally.
  • Loading branch information
mvo5 committed Dec 16, 2024
1 parent c46d125 commit ad9d53a
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion bib/internal/progress/progress.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,17 @@ func (b *terminalProgressBar) SetProgress(subLevel int, msg string, done int, to
switch {
case subLevel == len(b.subLevelPbs):
apb := pb.New(0)
b.subLevelPbs = append(b.subLevelPbs, apb)
progressBarTmpl := `[{{ counters . }}] {{ string . "prefix" }} {{ bar .}} {{ percent . }}`
apb.SetTemplateString(progressBarTmpl)
if err := apb.Err(); err != nil {
return fmt.Errorf("error setting the progressbarTemplat: %w", err)
}
// workaround bug when running tests in tmt
if apb.Width() == 0 {
// this is pb.defaultBarWidth
apb.SetWidth(100)
}
b.subLevelPbs = append(b.subLevelPbs, apb)
case subLevel > len(b.subLevelPbs):
return fmt.Errorf("sublevel added out of order, have %v sublevels but want level %v", len(b.subLevelPbs), subLevel)
}
Expand Down

0 comments on commit ad9d53a

Please sign in to comment.