MCPcopy Create free account
hub / github.com/MiniCodeMonkey/chief / centerModal

Method centerModal

internal/tui/help.go:255–293  ·  view source on GitHub ↗

centerModal centers the modal on the screen.

(modal string)

Source from the content-addressed store, hash-verified

253
254// centerModal centers the modal on the screen.
255func (h *HelpOverlay) centerModal(modal string) string {
256 lines := strings.Split(modal, "\n")
257 modalHeight := len(lines)
258 modalWidth := 0
259 for _, line := range lines {
260 if lipgloss.Width(line) > modalWidth {
261 modalWidth = lipgloss.Width(line)
262 }
263 }
264
265 // Calculate padding
266 topPadding := (h.height - modalHeight) / 2
267 leftPadding := (h.width - modalWidth) / 2
268
269 if topPadding < 0 {
270 topPadding = 0
271 }
272 if leftPadding < 0 {
273 leftPadding = 0
274 }
275
276 // Build centered content
277 var result strings.Builder
278
279 // Top padding
280 for i := 0; i < topPadding; i++ {
281 result.WriteString("\n")
282 }
283
284 // Modal lines with left padding
285 leftPad := strings.Repeat(" ", leftPadding)
286 for _, line := range lines {
287 result.WriteString(leftPad)
288 result.WriteString(line)
289 result.WriteString("\n")
290 }
291
292 return result.String()
293}

Callers 1

RenderMethod · 0.95

Calls 1

StringMethod · 0.45

Tested by

no test coverage detected