From 1cdfb5653143119671bd7746db37f60db330a1c3 Mon Sep 17 00:00:00 2001 From: Moira Daniella sebastian <167986620+MoiraDaniellaSebastian@users.noreply.github.com> Date: Tue, 10 Mar 2026 15:05:41 +0100 Subject: [PATCH] Update pkg/tui/components/modals.go Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- pkg/tui/components/modals.go | 43 +++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/pkg/tui/components/modals.go b/pkg/tui/components/modals.go index 3541b5f..1ca6ee1 100644 --- a/pkg/tui/components/modals.go +++ b/pkg/tui/components/modals.go @@ -150,14 +150,55 @@ func RenderModals( // RenderFooter renders the shared footer with the help bar and optional // validation feedback message. + +// truncateToWidth trims the given text so that its rendered width does not +// exceed maxWidth. If truncation occurs and there is room, an ellipsis is +// appended to indicate that the text was shortened. +func truncateToWidth(text string, maxWidth int) string { + if maxWidth <= 0 { + return "" + } + + if lipgloss.Width(text) <= maxWidth { + return text + } + + const ellipsis = "…" + ellipsisWidth := lipgloss.Width(ellipsis) + if ellipsisWidth > maxWidth { + // Not enough space even for an ellipsis; return empty. + return "" + } + + runes := []rune(text) + current := "" + for _, r := range runes { + next := current + string(r) + if lipgloss.Width(next)+ellipsisWidth > maxWidth { + break + } + current = next + } + + return current + ellipsis +} + func RenderFooter(width int, helpBar *HelpBar, feedback models.ValidationFeedback) string { feedbackStatus := feedback.Message + // Ensure the feedback message does not exceed the total available width. + feedbackStatus = truncateToWidth(feedbackStatus, width) + if feedbackStatus == "" { return helpBar.View() } - helpBar.SetWidth(width - lipgloss.Width(feedbackStatus)) + helpWidth := width - lipgloss.Width(feedbackStatus) + if helpWidth < 0 { + helpWidth = 0 + } + + helpBar.SetWidth(helpWidth) return lipgloss.JoinHorizontal(lipgloss.Left, helpBar.View(), feedbackStatus) }