[PR #9079] [MERGED] cmd: fix flickering in progress bar #12852

Closed
opened 2026-04-13 00:11:15 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ollama/ollama/pull/9079
Author: @jeremyschlatter
Created: 2/14/2025
Status: Merged
Merged: 2/18/2025
Merged by: @mxyng

Base: mainHead: main


📝 Commits (4)

  • faf67db cmd: fix progress bar flickering
  • 5930aae cmd: fix cursor flickering in progress bar
  • f9c7ead cmd: eliminate flickering with synchronized output
  • 78f403f address code review comments

📊 Changes

1 file changed (+18 additions, -9 deletions)

View changed files

📝 progress/progress.go (+18 -9)

📄 Description

In some cases the progress bar flickers during model downloads. This is caused by the way the progress bar was issuing screen updates: first clearing the screen, then drawing the new content. If the terminal emulator renders a frame between clearing and printing new content, then what shows up is empty space. Toggle rapidly between the empty space and the normal content, and you get flickering.

This PR adds three fixes to resolve the flickering as thoroughly as possible.

  1. There is a terminal mode called synchronized output designed exactly for this purpose: to make sure the terminal does not render partial state updates. This PR adds synchronized output to resolve the issue on terminals that support this mode.

  2. Instead of clearing-then-drawing, we can just write the new content directly over the old content. For cases where the new content is shorter, issue a \033[K at the end to clear the trailing end of the line. This way there is never a moment when the content is blank, so there is no flickering regardless of when the terminal happens to render new frames.

  3. Output buffering. Rather than emitting partial content updates as they are ready (clearing one line at a time, then rendering one line at a time), we can write all of the partial updates to a buffer and then write out that buffer all at once. This significantly decreases the window of time in which the terminal can only see a partial update. This is particularly relevant for cursor flickering. While the changes in (2) fix flickering in the progress bar itself, they do not prevent the cursor from flickering. While cursor flickering is harder to fix completely, output buffering significantly reduces it. Output buffering also decreases the chances that a synchronized output terminal (1) times out while we are rendering an update.

Before:

https://github.com/user-attachments/assets/655a994e-c8f1-40e5-bffa-d22d8879a8f8

After:

https://github.com/user-attachments/assets/e855cac9-ec7a-4a56-b648-9ff989c8c204

Fixes #1664


🔄 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/9079 **Author:** [@jeremyschlatter](https://github.com/jeremyschlatter) **Created:** 2/14/2025 **Status:** ✅ Merged **Merged:** 2/18/2025 **Merged by:** [@mxyng](https://github.com/mxyng) **Base:** `main` ← **Head:** `main` --- ### 📝 Commits (4) - [`faf67db`](https://github.com/ollama/ollama/commit/faf67db089c6b2168fb1bab99b4385d374c64efe) cmd: fix progress bar flickering - [`5930aae`](https://github.com/ollama/ollama/commit/5930aaeb1ae420eb9a0963247ff4463d1eadce5a) cmd: fix cursor flickering in progress bar - [`f9c7ead`](https://github.com/ollama/ollama/commit/f9c7ead1601f286d619e4d6988cd2da2c86474ce) cmd: eliminate flickering with synchronized output - [`78f403f`](https://github.com/ollama/ollama/commit/78f403ff4530441cd9c32198e0a4f9e9f8284f45) address code review comments ### 📊 Changes **1 file changed** (+18 additions, -9 deletions) <details> <summary>View changed files</summary> 📝 `progress/progress.go` (+18 -9) </details> ### 📄 Description In some cases the progress bar flickers during model downloads. This is caused by the way the progress bar was issuing screen updates: first clearing the screen, then drawing the new content. If the terminal emulator renders a frame between clearing and printing new content, then what shows up is empty space. Toggle rapidly between the empty space and the normal content, and you get flickering. This PR adds three fixes to resolve the flickering as thoroughly as possible. 1. There is a terminal mode called [synchronized output](https://gist.github.com/christianparpart/d8a62cc1ab659194337d73e399004036) designed exactly for this purpose: to make sure the terminal does not render partial state updates. This PR adds synchronized output to resolve the issue on terminals that support this mode. 2. Instead of clearing-then-drawing, we can just write the new content directly over the old content. For cases where the new content is shorter, issue a `\033[K` at the end to clear the trailing end of the line. This way there is never a moment when the content is blank, so there is no flickering regardless of when the terminal happens to render new frames. 3. Output buffering. Rather than emitting partial content updates as they are ready (clearing one line at a time, then rendering one line at a time), we can write all of the partial updates to a buffer and then write out that buffer all at once. This significantly decreases the window of time in which the terminal can only see a partial update. This is particularly relevant for cursor flickering. While the changes in (2) fix flickering in the progress bar itself, they do not prevent the cursor from flickering. While cursor flickering is harder to fix completely, output buffering significantly reduces it. Output buffering also decreases the chances that a synchronized output terminal (1) times out while we are rendering an update. Before: https://github.com/user-attachments/assets/655a994e-c8f1-40e5-bffa-d22d8879a8f8 After: https://github.com/user-attachments/assets/e855cac9-ec7a-4a56-b648-9ff989c8c204 Fixes #1664 --- <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-13 00:11:15 -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#12852