MCPcopy Create free account
hub / github.com/OverloadBlitz/cloudcent-cli / injectBorderTitle

Function injectBorderTitle

internal/tui/views/utils.go:76–101  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

74// injectBorderTitle replaces the first line (top border) of a lipgloss-rendered
75// box with a new top border containing styledTitle.
76func 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

Callers 2

boxWithTitleFunction · 0.85
boxWithTitleMinHeightFunction · 0.85

Calls 1

RenderMethod · 0.45

Tested by

no test coverage detected