From 2cc9392e2b00d0ea808fdb120a27f71a8588cfd9 Mon Sep 17 00:00:00 2001 From: swanadiva Date: Tue, 23 Jun 2026 19:15:21 +0700 Subject: [PATCH] =?UTF-8?q?fix:=20SFTP=20pane=20truncation=20=E2=80=94=20u?= =?UTF-8?q?se=20lipgloss.Width=20instead=20of=20len(),=20account=20for=20b?= =?UTF-8?q?order+padding=20overhead,=20compact=20file=20listing=20on=20nar?= =?UTF-8?q?row=20panes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/tui/sftp_browser_tab.go | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/pkg/tui/sftp_browser_tab.go b/pkg/tui/sftp_browser_tab.go index 1d55c4c..6d351e9 100644 --- a/pkg/tui/sftp_browser_tab.go +++ b/pkg/tui/sftp_browser_tab.go @@ -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 {