diff --git a/pkg/tui/tui.go b/pkg/tui/tui.go index 43ad6bb..7455828 100644 --- a/pkg/tui/tui.go +++ b/pkg/tui/tui.go @@ -22,6 +22,7 @@ import ( "github.com/charmbracelet/bubbles/viewport" tea "github.com/charmbracelet/bubbletea" "github.com/charmbracelet/lipgloss" + "github.com/muesli/reflow/ansi" "github.com/muesli/reflow/wordwrap" ) @@ -411,9 +412,15 @@ func (m *model) footerView() string { footer := left + padding + right if remaining < 0 { ellipses := "... " - // this doesn't work very well, due to trying to trim a string with - // ansii chars already in it - footer = footer[:(len(footer)+remaining)-len(ellipses)-3] + ellipses + for { + truncWidth := ansi.PrintableRuneWidth(footer) + len(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) }