tui: improve footer truncation
This commit is contained in:
parent
ef929da68c
commit
6310021dca
@ -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)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user