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"
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)
}