[PR #553] [MERGED] add word wrapping for lines which are longer than the terminal width #72509

Closed
opened 2026-05-05 04:03:17 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ollama/ollama/pull/553
Author: @pdevine
Created: 9/19/2023
Status: Merged
Merged: 9/22/2023
Merged by: @pdevine

Base: mainHead: wordwrap


📝 Commits (3)

  • f17ecb1 add word wrapping for lines which are longer than the terminal width
  • dfc43b5 add ability to turn wordwrap on/off
  • 8f95933 fix typo

📊 Changes

2 files changed (+65 additions, -25 deletions)

View changed files

📝 cmd/cmd.go (+65 -24)
📝 go.sum (+0 -1)

📄 Description

This change makes it so the REPL will properly wrap a line on a word boundary. The way it works is that it walks through each character of each token returned by the server, and then keeps a buffer of the last word. If the maximum boundary length is exceeded, it will backtrack using ANSI escape codes to the length of the current word buffer, erase to the end of the line, give a line feed, and then add the word fragment to the new line. This requires that the terminal allow ANSI graphics which should be OK for any modern terminal. If you run this headless, it will default to not wrapping any lines.

Right now I've set the width to 5 characters less than the terminal width, but we can potentially make this a setting in the future.

This fixes issue #150


🔄 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/553 **Author:** [@pdevine](https://github.com/pdevine) **Created:** 9/19/2023 **Status:** ✅ Merged **Merged:** 9/22/2023 **Merged by:** [@pdevine](https://github.com/pdevine) **Base:** `main` ← **Head:** `wordwrap` --- ### 📝 Commits (3) - [`f17ecb1`](https://github.com/ollama/ollama/commit/f17ecb13aa055de2ef2de8bb988c5cbabb011d86) add word wrapping for lines which are longer than the terminal width - [`dfc43b5`](https://github.com/ollama/ollama/commit/dfc43b5c97a9f2ffaea52973b9051a42bbf646ea) add ability to turn wordwrap on/off - [`8f95933`](https://github.com/ollama/ollama/commit/8f95933f16e46bb50d6079e996de7bcd2953d0cb) fix typo ### 📊 Changes **2 files changed** (+65 additions, -25 deletions) <details> <summary>View changed files</summary> 📝 `cmd/cmd.go` (+65 -24) 📝 `go.sum` (+0 -1) </details> ### 📄 Description This change makes it so the REPL will properly wrap a line on a word boundary. The way it works is that it walks through each character of each token returned by the server, and then keeps a buffer of the last word. If the maximum boundary length is exceeded, it will backtrack using ANSI escape codes to the length of the current word buffer, erase to the end of the line, give a line feed, and then add the word fragment to the new line. This requires that the terminal allow ANSI graphics which should be OK for any modern terminal. If you run this headless, it will default to not wrapping any lines. Right now I've set the width to 5 characters less than the terminal width, but we can potentially make this a setting in the future. This fixes issue #150 --- <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-05-05 04:03:17 -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#72509