Skip to content

Commit

Permalink
Fixed error when terminal size was too small
Browse files Browse the repository at this point in the history
  • Loading branch information
acidvegas committed Dec 6, 2024
1 parent 413c365 commit d24c806
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions ptrstream.go
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ func main() {
app.QueueUpdateDraw(func() {
var width int
_, _, width, _ = progress.GetInnerRect()
if width == 0 {
if width <= 0 {
return
}

Expand All @@ -465,7 +465,17 @@ func main() {
formatNumber(failed),
float64(failed)/float64(processed)*100)

barWidth := width - visibleLength(statsText) - 2
textWidth := visibleLength(statsText)
barWidth := width - textWidth - 2 // -2 for the [] characters

// Ensure barWidth is at least 1
if barWidth < 1 {
// If there's not enough space, just show the stats without the progress bar
progress.Clear()
fmt.Fprint(progress, statsText)
return
}

filled := int(float64(barWidth) * (percent / 100))
if filled > barWidth {
filled = barWidth
Expand Down

0 comments on commit d24c806

Please sign in to comment.