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

Method centerModal

internal/tui/branch_warning.go:372–410  ·  view source on GitHub ↗

centerModal centers the modal on the screen.

(modal string)

Source from the content-addressed store, hash-verified

370
371// centerModal centers the modal on the screen.
372func (b *BranchWarning) centerModal(modal string) string {
373 lines := strings.Split(modal, "\n")
374 modalHeight := len(lines)
375 modalWidth := 0
376 for _, line := range lines {
377 if lipgloss.Width(line) > modalWidth {
378 modalWidth = lipgloss.Width(line)
379 }
380 }
381
382 // Calculate padding
383 topPadding := (b.height - modalHeight) / 2
384 leftPadding := (b.width - modalWidth) / 2
385
386 if topPadding < 0 {
387 topPadding = 0
388 }
389 if leftPadding < 0 {
390 leftPadding = 0
391 }
392
393 // Build centered content
394 var result strings.Builder
395
396 // Top padding
397 for i := 0; i < topPadding; i++ {
398 result.WriteString("\n")
399 }
400
401 // Modal lines with left padding
402 leftPad := strings.Repeat(" ", leftPadding)
403 for _, line := range lines {
404 result.WriteString(leftPad)
405 result.WriteString(line)
406 result.WriteString("\n")
407 }
408
409 return result.String()
410}

Callers 1

RenderMethod · 0.95

Calls 1

StringMethod · 0.45

Tested by

no test coverage detected