[PR #14873] fix: prevent negative term width in progress bar #61583

Open
opened 2026-04-29 16:39:20 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ollama/ollama/pull/14873
Author: @LincolnBurrows2017
Created: 3/16/2026
Status: 🔄 Open

Base: mainHead: fix/term-width-bounds


📝 Commits (3)

  • 187cc62 fix: handle errors properly in API client and envconfig LogLevel
  • 7992e0f fix: prevent negative term width in progress bar
  • 6581f90 fix: prevent division by zero when prompt exceeds terminal width

📊 Changes

4 files changed (+19 additions, -4 deletions)

View changed files

📝 api/client.go (+4 -1)
📝 envconfig/config.go (+9 -3)
📝 progress/bar.go (+3 -0)
📝 readline/buffer.go (+3 -0)

📄 Description

Description

When the terminal width is smaller than the minimum required for the progress bar, the calculation of available width (f) can become negative. This fix adds a bounds check to ensure f is never negative, preventing potential issues with the progress bar rendering.

Reproduction

The issue occurs when the terminal width is very small (less than ~30 characters), causing the calculation termWidth - pre.Len() - suf.Len() - 5 to become negative.

Fix

Add a bounds check to ensure f is never negative before using it in the progress bar rendering.

if f < 0 {
    f = 0
}

This ensures the progress bar renders correctly even in narrow terminals.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ollama/ollama/pull/14873 **Author:** [@LincolnBurrows2017](https://github.com/LincolnBurrows2017) **Created:** 3/16/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/term-width-bounds` --- ### 📝 Commits (3) - [`187cc62`](https://github.com/ollama/ollama/commit/187cc62a1afd34c59921ad156752ca94e6492df5) fix: handle errors properly in API client and envconfig LogLevel - [`7992e0f`](https://github.com/ollama/ollama/commit/7992e0fe7d0e4a1f9548790b711dd5f17bac0156) fix: prevent negative term width in progress bar - [`6581f90`](https://github.com/ollama/ollama/commit/6581f902ee86d84cd9b29e491754fe09835290c7) fix: prevent division by zero when prompt exceeds terminal width ### 📊 Changes **4 files changed** (+19 additions, -4 deletions) <details> <summary>View changed files</summary> 📝 `api/client.go` (+4 -1) 📝 `envconfig/config.go` (+9 -3) 📝 `progress/bar.go` (+3 -0) 📝 `readline/buffer.go` (+3 -0) </details> ### 📄 Description ## Description When the terminal width is smaller than the minimum required for the progress bar, the calculation of available width (`f`) can become negative. This fix adds a bounds check to ensure `f` is never negative, preventing potential issues with the progress bar rendering. ## Reproduction The issue occurs when the terminal width is very small (less than ~30 characters), causing the calculation `termWidth - pre.Len() - suf.Len() - 5` to become negative. ## Fix Add a bounds check to ensure `f` is never negative before using it in the progress bar rendering. ```go if f < 0 { f = 0 } ``` This ensures the progress bar renders correctly even in narrow terminals. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-04-29 16:39:20 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/ollama#61583