From 1cf558dff2b0de8b63f0f49043b28a0c420e7988 Mon Sep 17 00:00:00 2001 From: Navid Yaghoobi Date: Sun, 6 Nov 2022 17:14:54 +1100 Subject: [PATCH] fix panic caused by gauge default maxValue Signed-off-by: Navid Yaghoobi --- gauge_pm.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/gauge_pm.go b/gauge_pm.go index aa7881d..0cb91c2 100644 --- a/gauge_pm.go +++ b/gauge_pm.go @@ -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 @@ -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