tui: improve footer truncation

This commit is contained in:
Matt Low 2024-03-23 03:59:02 +00:00
parent ef929da68c
commit 6310021dca

View File

@ -22,6 +22,7 @@ import (
"github.com/charmbracelet/bubbles/viewport" "github.com/charmbracelet/bubbles/viewport"
tea "github.com/charmbracelet/bubbletea" tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss" "github.com/charmbracelet/lipgloss"
"github.com/muesli/reflow/ansi"
"github.com/muesli/reflow/wordwrap" "github.com/muesli/reflow/wordwrap"
) )
@ -411,9 +412,15 @@ func (m *model) footerView() string {
footer := left + padding + right footer := left + padding + right
if remaining < 0 { if remaining < 0 {
ellipses := "... " ellipses := "... "
// this doesn't work very well, due to trying to trim a string with for {
// ansii chars already in it truncWidth := ansi.PrintableRuneWidth(footer) + len(ellipses)
footer = footer[:(len(footer)+remaining)-len(ellipses)-3] + ellipses if truncWidth <= m.width {
break
}
// truncate the minimum amount, not accounting for printed width
footer = footer[:len(footer)-(truncWidth-m.width)]
}
footer += ellipses
} }
return footerStyle.Width(m.width).Render(footer) return footerStyle.Width(m.width).Render(footer)
} }