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:
@@ -601,6 +601,12 @@ func (t *SFTPBrowserTab) renderPane(p *sftpPane, pt paneType, maxW int) string {
|
|||||||
paneStyle = StylePaneActive
|
paneStyle = StylePaneActive
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Inner content width: border(2) + padding(2) = 4 overhead
|
||||||
|
innerW := maxW - 4
|
||||||
|
if innerW < 5 {
|
||||||
|
innerW = 5
|
||||||
|
}
|
||||||
|
|
||||||
// Title
|
// Title
|
||||||
titleBar := fmt.Sprintf(" %s ", title)
|
titleBar := fmt.Sprintf(" %s ", title)
|
||||||
if isActive {
|
if isActive {
|
||||||
@@ -609,14 +615,14 @@ func (t *SFTPBrowserTab) renderPane(p *sftpPane, pt paneType, maxW int) string {
|
|||||||
titleBar = SubtitleStyle.Render(" " + title + " ")
|
titleBar = SubtitleStyle.Render(" " + title + " ")
|
||||||
}
|
}
|
||||||
|
|
||||||
// CWD
|
// CWD (truncated with proper visual width)
|
||||||
cwdStr := p.cwd
|
cwdDisplay := fmt.Sprintf(" %s", p.cwd)
|
||||||
if len(cwdStr) > maxW-4 {
|
if lipgloss.Width(cwdDisplay) > innerW {
|
||||||
cwdStr = "..." + cwdStr[len(cwdStr)-maxW+7:]
|
cwdDisplay = truncateStr(cwdDisplay, innerW)
|
||||||
}
|
}
|
||||||
|
|
||||||
var content strings.Builder
|
var content strings.Builder
|
||||||
content.WriteString(SubtitleStyle.Render(fmt.Sprintf(" %s", cwdStr)))
|
content.WriteString(SubtitleStyle.Render(cwdDisplay))
|
||||||
content.WriteString("\n\n")
|
content.WriteString("\n\n")
|
||||||
|
|
||||||
// Filter
|
// Filter
|
||||||
@@ -655,13 +661,20 @@ func (t *SFTPBrowserTab) renderPane(p *sftpPane, pt paneType, maxW int) string {
|
|||||||
|
|
||||||
if entry.IsDir() {
|
if entry.IsDir() {
|
||||||
line = fmt.Sprintf(" %s/", name)
|
line = fmt.Sprintf(" %s/", name)
|
||||||
|
} else if innerW < 30 {
|
||||||
|
line = fmt.Sprintf(" %s", name)
|
||||||
} else {
|
} else {
|
||||||
size := formatSize(entry.Size())
|
size := formatSize(entry.Size())
|
||||||
line = fmt.Sprintf(" %s (%s)", name, size)
|
line = fmt.Sprintf(" %s (%s)", name, size)
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(line) > maxW {
|
// Truncate — account for SelectedStyle Padding(0,1) = 2 extra chars
|
||||||
line = line[:maxW-1] + "…"
|
lineMaxW := innerW
|
||||||
|
if i == p.selIdx {
|
||||||
|
lineMaxW = innerW - 2
|
||||||
|
}
|
||||||
|
if lipgloss.Width(line) > lineMaxW {
|
||||||
|
line = truncateStr(line, lineMaxW)
|
||||||
}
|
}
|
||||||
|
|
||||||
if i == p.selIdx {
|
if i == p.selIdx {
|
||||||
|
|||||||
Reference in New Issue
Block a user