[PR #2983] [CLOSED] Get term size from stderr and /dev/tty to avoid redirection caused getting size error. #21560

Closed
opened 2026-04-19 15:43:15 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ollama/ollama/pull/2983
Author: @powerfooI
Created: 3/7/2024
Status: Closed

Base: mainHead: fix/redirect-err-term-size


📝 Commits (3)

  • 15efa1c fix(buf): #2970 get term size from stderr and /dev/tty
  • eb7a7ec fix(buffer): set default term size if getTermSize() fails
  • bca3705 chore(buffer): use errors.Join to combine all possible errors when trying to get term size from stdout, stderr, and /dev/tty

📊 Changes

2 files changed (+38 additions, -6 deletions)

View changed files

📝 readline/buffer.go (+34 -5)
📝 readline/readline.go (+4 -1)

📄 Description

As issue #2970 said, ollama run phi | tee llms/out.txt leads to error. When using a pipe operator following the ollama command theos.Stdout points to a pipe instead of the terminal, so term.Getsize failed.

Now the code gets terminal size from stderr first, which enables ollama run phi | tee llms/out.txt to execute normally.
If the user enter ollama run phi 2>&1 | tee llms/out.txt, the code then tries to get /dev/tty instead.


🔄 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/2983 **Author:** [@powerfooI](https://github.com/powerfooI) **Created:** 3/7/2024 **Status:** ❌ Closed **Base:** `main` ← **Head:** `fix/redirect-err-term-size` --- ### 📝 Commits (3) - [`15efa1c`](https://github.com/ollama/ollama/commit/15efa1c5625fcd8809930749e61fcc55a74678ef) fix(buf): #2970 get term size from stderr and /dev/tty - [`eb7a7ec`](https://github.com/ollama/ollama/commit/eb7a7ecdfee194609e57b6deae9e15919fa5e1fb) fix(buffer): set default term size if getTermSize() fails - [`bca3705`](https://github.com/ollama/ollama/commit/bca3705f2df0203f3b1afdcf550ccce713ced0d5) chore(buffer): use errors.Join to combine all possible errors when trying to get term size from stdout, stderr, and /dev/tty ### 📊 Changes **2 files changed** (+38 additions, -6 deletions) <details> <summary>View changed files</summary> 📝 `readline/buffer.go` (+34 -5) 📝 `readline/readline.go` (+4 -1) </details> ### 📄 Description As issue #2970 said, `ollama run phi | tee llms/out.txt` leads to error. When using a pipe operator following the `ollama` command the`os.Stdout` points to a pipe instead of the terminal, so `term.Getsize` failed. Now the code gets terminal size from stderr first, which enables `ollama run phi | tee llms/out.txt` to execute normally. If the user enter `ollama run phi 2>&1 | tee llms/out.txt`, the code then tries to get `/dev/tty` instead. --- <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-19 15:43: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#21560