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

Method centerModal

internal/tui/picker.go:1002–1040  ·  view source on GitHub ↗

centerModal centers the modal on the screen.

(modal string)

Source from the content-addressed store, hash-verified

1000
1001// centerModal centers the modal on the screen.
1002func (p *PRDPicker) centerModal(modal string) string {
1003 lines := strings.Split(modal, "\n")
1004 modalHeight := len(lines)
1005 modalWidth := 0
1006 for _, line := range lines {
1007 if lipgloss.Width(line) > modalWidth {
1008 modalWidth = lipgloss.Width(line)
1009 }
1010 }
1011
1012 // Calculate padding
1013 topPadding := (p.height - modalHeight) / 2
1014 leftPadding := (p.width - modalWidth) / 2
1015
1016 if topPadding < 0 {
1017 topPadding = 0
1018 }
1019 if leftPadding < 0 {
1020 leftPadding = 0
1021 }
1022
1023 // Build centered content
1024 var result strings.Builder
1025
1026 // Top padding
1027 for i := 0; i < topPadding; i++ {
1028 result.WriteString("\n")
1029 }
1030
1031 // Modal lines with left padding
1032 leftPad := strings.Repeat(" ", leftPadding)
1033 for _, line := range lines {
1034 result.WriteString(leftPad)
1035 result.WriteString(line)
1036 result.WriteString("\n")
1037 }
1038
1039 return result.String()
1040}

Callers 4

RenderMethod · 0.95
renderMergeResultMethod · 0.95
renderCleanResultMethod · 0.95

Calls 1

StringMethod · 0.45

Tested by

no test coverage detected