fix column black bars for file names with multibyte characters - #22
fix column black bars for file names with multibyte characters#22gmist wants to merge 17 commits into
Conversation
Automated code reviewNice catch on the root cause — 1. The column shift is still reproducible (blocking)
Affected: Fix is to pad after truncating: out := ansi.Truncate(s, width-3, "") + "..."
return out + strings.Repeat(" ", width-ansi.StringWidth(out))The same shape is latent in Side note: 2. New infinite loop in
|
Problem
When a folder contains files with non-ASCII names, the file panel breaks: black bars appear in the row of such files and the size and date columns shift out of place.

Cause
The code measured name length with
len(s)and padded or cut strings by that value.len(s)returns the number of bytes, not the number of visible characters. Many characters take more than one byte in UTF-8 but occupy only one cell on the screen. So for a name likegröße.txt:len()reports 11the terminal shows 9 cells
All column math was based on the wrong number. Cutting by byte index could also split one character in half which produced broken characters.
Fix
All helper functions now measure width in terminal cells, not bytes:
ansi.StringWidthfor measureansi.Truncate,ansi.TruncateLeftfor to cut safelyThese functions from

github.com/charmbracelet/x/ansi. This package is already in dependencies: lipgloss and bubbletea use it. It measures strings the same way bubbletea draws them, so the panel grid always matches what the renderer puts on screen.