@@ -91,24 +91,32 @@ func (m Model) View() string {
9191 content := strings .Join (sections , "\n " )
9292 frame := frameStyle .Render (content )
9393
94- // Center horizontally and vertically within the terminal
94+ return m .centerFrame (frame )
95+ }
96+
97+ // centerFrame centers a pre-rendered frame in the terminal using plain string
98+ // padding instead of allocating a new lipgloss.Style every render.
99+ func (m Model ) centerFrame (frame string ) string {
95100 frameW := lipgloss .Width (frame )
96101 frameH := lipgloss .Height (frame )
97-
98102 padLeft := max (0 , (m .width - frameW )/ 2 )
99103 padTop := max (0 , (m .height - frameH )/ 2 )
100104
101- return strings .Repeat ("\n " , padTop ) +
102- lipgloss .NewStyle ().MarginLeft (padLeft ).Render (frame )
105+ if padLeft == 0 {
106+ return strings .Repeat ("\n " , padTop ) + frame
107+ }
108+ // Indent every line by padLeft spaces.
109+ prefix := strings .Repeat (" " , padLeft )
110+ lines := strings .Split (frame , "\n " )
111+ for i , l := range lines {
112+ lines [i ] = prefix + l
113+ }
114+ return strings .Repeat ("\n " , padTop ) + strings .Join (lines , "\n " )
103115}
104116
105117// centerOverlay wraps content in a frame and centers it in the terminal.
106118func (m Model ) centerOverlay (content string ) string {
107- frame := frameStyle .Render (content )
108- padLeft := max (0 , (m .width - lipgloss .Width (frame ))/ 2 )
109- padTop := max (0 , (m .height - lipgloss .Height (frame ))/ 2 )
110- return strings .Repeat ("\n " , padTop ) +
111- lipgloss .NewStyle ().MarginLeft (padLeft ).Render (frame )
119+ return m .centerFrame (frameStyle .Render (content ))
112120}
113121
114122func (m Model ) renderKeymapOverlay () string {
@@ -487,6 +495,9 @@ func (m Model) renderTimeStatus() string {
487495}
488496
489497func (m Model ) renderSpectrum () string {
498+ if m .vis .Mode == VisNone {
499+ return ""
500+ }
490501 bands := m .vis .Analyze (m .player .Samples ())
491502 return m .vis .Render (bands )
492503}
0 commit comments