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

Function centerModal

internal/tui/completion.go:581–615  ·  view source on GitHub ↗

centerModal centers a modal string on the screen.

(modal string, screenWidth, screenHeight int)

Source from the content-addressed store, hash-verified

579
580// centerModal centers a modal string on the screen.
581func centerModal(modal string, screenWidth, screenHeight int) string {
582 lines := strings.Split(modal, "\n")
583 modalHeight := len(lines)
584 modalWidth := 0
585 for _, line := range lines {
586 if lipgloss.Width(line) > modalWidth {
587 modalWidth = lipgloss.Width(line)
588 }
589 }
590
591 topPadding := (screenHeight - modalHeight) / 2
592 leftPadding := (screenWidth - modalWidth) / 2
593
594 if topPadding < 0 {
595 topPadding = 0
596 }
597 if leftPadding < 0 {
598 leftPadding = 0
599 }
600
601 var result strings.Builder
602
603 for i := 0; i < topPadding; i++ {
604 result.WriteString("\n")
605 }
606
607 leftPad := strings.Repeat(" ", leftPadding)
608 for _, line := range lines {
609 result.WriteString(leftPad)
610 result.WriteString(line)
611 result.WriteString("\n")
612 }
613
614 return result.String()
615}

Callers 3

RenderMethod · 0.85
RenderMethod · 0.85
TestCenterModalFunction · 0.85

Calls 1

StringMethod · 0.45

Tested by 1

TestCenterModalFunction · 0.68