Update pkg/tui/components/modals.go
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
a63edceb00
commit
1cdfb56531
@@ -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)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user