Skip to content

Commit

Permalink
fix panic caused by gauge default maxValue
Browse files Browse the repository at this point in the history
Signed-off-by: Navid Yaghoobi <[email protected]>
  • Loading branch information
navidys committed Nov 6, 2022
1 parent 0316a1e commit 1cf558d
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions gauge_pm.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ func NewPercentageModeGauge() *PercentageModeGauge {
// Draw draws this primitive onto the screen.
func (g *PercentageModeGauge) Draw(screen tcell.Screen) {
g.Box.DrawForSubclass(screen, g)

if g.maxValue == 0 {
return
}

x, y, width, height := g.Box.GetInnerRect()
pcWidth := 3
pc := g.value * gaugeMaxPc / g.maxValue
Expand Down Expand Up @@ -123,6 +128,10 @@ func (g *PercentageModeGauge) Reset() {
}

func (g *PercentageModeGauge) progressBlock(max int) int {
if g.maxValue == 0 {
return g.maxValue
}

pc := g.value * gaugeMaxPc / g.maxValue
value := pc * max / gaugeMaxPc

Expand Down

0 comments on commit 1cf558d

Please sign in to comment.