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

Method centerModal

internal/tui/worktree_spinner.go:247–280  ·  view source on GitHub ↗

centerModal centers the modal on the screen.

(modal string)

Source from the content-addressed store, hash-verified

245
246// centerModal centers the modal on the screen.
247func (w *WorktreeSpinner) centerModal(modal string) string {
248 lines := strings.Split(modal, "\n")
249 modalHeight := len(lines)
250 modalWidth := 0
251 for _, line := range lines {
252 if lipgloss.Width(line) > modalWidth {
253 modalWidth = lipgloss.Width(line)
254 }
255 }
256
257 topPadding := (w.height - modalHeight) / 2
258 leftPadding := (w.width - modalWidth) / 2
259
260 if topPadding < 0 {
261 topPadding = 0
262 }
263 if leftPadding < 0 {
264 leftPadding = 0
265 }
266
267 var result strings.Builder
268 for i := 0; i < topPadding; i++ {
269 result.WriteString("\n")
270 }
271
272 leftPad := strings.Repeat(" ", leftPadding)
273 for _, line := range lines {
274 result.WriteString(leftPad)
275 result.WriteString(line)
276 result.WriteString("\n")
277 }
278
279 return result.String()
280}

Callers 1

RenderMethod · 0.95

Calls 1

StringMethod · 0.45

Tested by

no test coverage detected