From 5b1b2b435cd805462e6c01fa6d3453bea0199166 Mon Sep 17 00:00:00 2001 From: Evan Wies Date: Thu, 21 May 2026 10:22:07 -0400 Subject: [PATCH] fix(ui): guard divide-by-zero display error Otherwise, if contextWindow == 0, then it's a divide-by-zero error and a wild number % is shown. Now it defaults to 0% in that case. Signed-off-by: Evan Wies --- internal/ui/common/elements.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/internal/ui/common/elements.go b/internal/ui/common/elements.go index 2cdb9993b611cba768b99ee528b41a7634c7ef61..506824a34dfdad0a9d8cedb870c2e4066c62fdb5 100644 --- a/internal/ui/common/elements.go +++ b/internal/ui/common/elements.go @@ -111,7 +111,10 @@ func formatTokensAndCost(t *styles.Styles, tokens, contextWindow int64, cost flo formattedTokens = strings.Replace(formattedTokens, ".0M", "M", 1) } - percentage := (float64(tokens) / float64(contextWindow)) * 100 + var percentage float64 + if contextWindow > 0 { + percentage = (float64(tokens) / float64(contextWindow)) * 100 + } formattedCost := t.ModelInfo.Cost.Render(fmt.Sprintf("$%.2f", cost))