injectBorderTitle replaces the first line (top border) of a lipgloss-rendered box with a new top border containing styledTitle.
(rendered, styledTitle string, titleWidth int, borderColor lipgloss.Color)
| 74 | // injectBorderTitle replaces the first line (top border) of a lipgloss-rendered |
| 75 | // box with a new top border containing styledTitle. |
| 76 | func injectBorderTitle(rendered, styledTitle string, titleWidth int, borderColor lipgloss.Color) string { |
| 77 | bs := lipgloss.NewStyle().Foreground(borderColor) |
| 78 | |
| 79 | idx := strings.IndexByte(rendered, '\n') |
| 80 | var topLine, rest string |
| 81 | if idx >= 0 { |
| 82 | topLine = rendered[:idx] |
| 83 | rest = rendered[idx:] // includes the \n |
| 84 | } else { |
| 85 | topLine = rendered |
| 86 | rest = "" |
| 87 | } |
| 88 | |
| 89 | topWidth := lipgloss.Width(topLine) |
| 90 | innerWidth := topWidth - 2 // strip ╭ and ╮ |
| 91 | |
| 92 | // ╭─ <title> <rightDashes>╮ |
| 93 | // visual width: 1+1+1 + titleWidth + 1 + rightDashes + 1 = topWidth |
| 94 | rightDashes := innerWidth - 3 - titleWidth |
| 95 | if rightDashes < 0 { |
| 96 | rightDashes = 0 |
| 97 | } |
| 98 | |
| 99 | newTop := bs.Render("╭─ ") + styledTitle + bs.Render(" "+strings.Repeat("─", rightDashes)+"╮") |
| 100 | return newTop + rest |
| 101 | } |
| 102 | |
| 103 | // renderNavHeader builds the shared navigation header box used by every view. |
| 104 | // activeView is the name of the currently active view (must match an entry in |
no test coverage detected