Skip to content

fix(ui): rendering issues when opening files with -t flag#887

Open
dhanush0x96c wants to merge 1 commit intocharmbracelet:masterfrom
dhanush0x96c:fix/tui-render
Open

fix(ui): rendering issues when opening files with -t flag#887
dhanush0x96c wants to merge 1 commit intocharmbracelet:masterfrom
dhanush0x96c:fix/tui-render

Conversation

@dhanush0x96c
Copy link
Copy Markdown

Fixes #878

Problem

When opening a file directly in TUI mode (glow -t README.md or glow -w 60 -t README.md), the -w (word wrap width) flag was ignored. The word wrap only took effect after escaping from edit mode.

Root Cause

In ui/ui.go, the Init() function read the file content and passed it to renderWithGlamour() but never stored the body in currentDocument.Body. When the first WindowSizeMsg arrived (which sets the correct viewport dimensions), the pager attempted to re-render using currentDocument.Body — which was an empty string. This caused the initial render (done before viewport dimensions were known) to be discarded and replaced with a blank re-render, effectively ignoring the configured word wrap width.

Fix

Replaced the manual file read in Init() with loadLocalMarkdown(), which:

  1. Reads the file from disk
  2. Stores the content in currentDocument.Body
  3. Emits a fetchedMarkdownMsg that triggers rendering with the correct body

This ensures that when WindowSizeMsg triggers a re-render, currentDocument.Body contains the actual file content, and the word wrap width is applied correctly.

Changed File

  • ui/ui.go — Replaced inline file reading in Init() with a call to loadLocalMarkdown(&m.pager.currentDocument).

  • I have read CONTRIBUTING.md.

  • I have created a discussion that was approved by a maintainer (for new features).

When passing a file via the CLI with the TUI flag (-t), the -w flag was
ignored and window resizing would result in a blank screen. This was
caused by the file content not being stored in currentDocument.Body
during Init(). Consequently, the first WindowSizeMsg triggered a
re-render with an empty body, discarding the initial content.

Replaced manual file reading in Init() with loadLocalMarkdown() to
ensure the body is correctly stored and a fetchedMarkdownMsg is
emitted. This ensures content is preserved during re-renders and that
the word wrap width is correctly applied.

Fixes charmbracelet#878
@dhanush0x96c dhanush0x96c requested a review from a team as a code owner February 19, 2026 19:21
@dhanush0x96c dhanush0x96c requested review from aymanbagabas and raphamorim and removed request for a team February 19, 2026 19:21
@dhanush0x96c
Copy link
Copy Markdown
Author

Hey @aymanbagabas and @raphamorim! Just a gentle ping on this PR when you get a chance. Would really appreciate your feedback 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TUI mode does not follow "-w"

1 participant