fix: SFTP pane truncation — use lipgloss.Width instead of len(), account for border+padding overhead, compact file listing on narrow panes

This commit is contained in:
swanadiva
2026-06-23 19:15:21 +07:00
parent d75621e9b4
commit 2cc9392e2b
+20 -7
View File
@@ -601,6 +601,12 @@ func (t *SFTPBrowserTab) renderPane(p *sftpPane, pt paneType, maxW int) string {
paneStyle = StylePaneActive
}
// Inner content width: border(2) + padding(2) = 4 overhead
innerW := maxW - 4
if innerW < 5 {
innerW = 5
}
// Title
titleBar := fmt.Sprintf(" %s ", title)
if isActive {
@@ -609,14 +615,14 @@ func (t *SFTPBrowserTab) renderPane(p *sftpPane, pt paneType, maxW int) string {
titleBar = SubtitleStyle.Render(" " + title + " ")
}
// CWD
cwdStr := p.cwd
if len(cwdStr) > maxW-4 {
cwdStr = "..." + cwdStr[len(cwdStr)-maxW+7:]
// CWD (truncated with proper visual width)
cwdDisplay := fmt.Sprintf(" %s", p.cwd)
if lipgloss.Width(cwdDisplay) > innerW {
cwdDisplay = truncateStr(cwdDisplay, innerW)
}
var content strings.Builder
content.WriteString(SubtitleStyle.Render(fmt.Sprintf(" %s", cwdStr)))
content.WriteString(SubtitleStyle.Render(cwdDisplay))
content.WriteString("\n\n")
// Filter
@@ -655,13 +661,20 @@ func (t *SFTPBrowserTab) renderPane(p *sftpPane, pt paneType, maxW int) string {
if entry.IsDir() {
line = fmt.Sprintf(" %s/", name)
} else if innerW < 30 {
line = fmt.Sprintf(" %s", name)
} else {
size := formatSize(entry.Size())
line = fmt.Sprintf(" %s (%s)", name, size)
}
if len(line) > maxW {
line = line[:maxW-1] + "…"
// Truncate — account for SelectedStyle Padding(0,1) = 2 extra chars
lineMaxW := innerW
if i == p.selIdx {
lineMaxW = innerW - 2
}
if lipgloss.Width(line) > lineMaxW {
line = truncateStr(line, lineMaxW)
}
if i == p.selIdx {