Skip to content

Commit bfd01b4

Browse files
authored
fix(ui): truncate long strings in footer (#68)
1 parent af443bb commit bfd01b4

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

internal/ui/view.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -164,12 +164,12 @@ func (m model) BaseView() string {
164164
)
165165
}
166166

167-
func truncate(s string, w int) string {
168-
if w <= 1 {
167+
func truncate(s string, width int) string {
168+
if width <= 1 {
169169
return ""
170170
}
171-
if len(s) > w {
172-
return s[:w-1] + "…"
171+
if len(s) > width {
172+
return s[:width-1] + "…"
173173
}
174174
return s
175175
}
@@ -648,9 +648,11 @@ func footerInformation(m model, width int) string {
648648
if topRowGap < 0 {
649649
topRowGap = 0
650650
}
651+
652+
truncatedTitle := truncate(songTitle, width-runewidth.StringWidth(notifcationStatus))
651653
topRow = lipgloss.JoinHorizontal(
652654
lipgloss.Center,
653-
lipgloss.NewStyle().Foreground(Theme.Highlight).Render(songTitle),
655+
lipgloss.NewStyle().Foreground(Theme.Highlight).Render(truncatedTitle),
654656
strings.Repeat(" ", topRowGap),
655657
notifcationStatus,
656658
)
@@ -685,9 +687,11 @@ func footerInformation(m model, width int) string {
685687
if middleRowGap < 0 {
686688
middleRowGap = 0
687689
}
690+
691+
truncatedSongAlbumArtistInfo := truncate(songAlbumArtistInfo, width-runewidth.StringWidth(loopStatus)-1-runewidth.StringWidth(volumeStatus))
688692
middleRow = lipgloss.JoinHorizontal(
689693
lipgloss.Center,
690-
songAlbumArtistInfo,
694+
truncatedSongAlbumArtistInfo,
691695
strings.Repeat(" ", middleRowGap),
692696
loopStatus,
693697
" ",

0 commit comments

Comments
 (0)