@@ -106,9 +106,9 @@ func NewLicenseWindow(licenseTitle, licenseContents, promptText string) *License
106106 licenseWindow .LayoutManager = func (g * gocui.Gui ) error {
107107 terminalWidth , terminalHeight := g .Size ()
108108
109- // Compute rectangles and validate them
110- lbx , lby , lex , ley , pbx , pby , pex , pey := computeLicenseAndPromptRects (terminalWidth , terminalHeight )
111- if err := validateLicenseRect ( lbx , lby , lex , ley ); err != nil {
109+ // Compute and validate rectangles
110+ lbx , lby , lex , ley , pbx , pby , pex , pey , err := computeLayoutRects (terminalWidth , terminalHeight )
111+ if err != nil {
112112 return err
113113 }
114114 if v , err := g .SetView ("license" , lbx , lby , lex , ley ); err != nil {
@@ -121,10 +121,6 @@ func NewLicenseWindow(licenseTitle, licenseContents, promptText string) *License
121121 fmt .Fprint (v , strings .ReplaceAll (licenseContents , "\r " , "" ))
122122 }
123123
124- // Prompt window dimensions
125- if err := validatePromptRect (pbx , pby , pex , pey ); err != nil {
126- return err
127- }
128124 if v , err := g .SetView ("prompt" , pbx , pby , pex , pey ); err != nil {
129125 if err != gocui .ErrUnknownView {
130126 log .Error ("Cannot modify prompt window: " , err )
@@ -133,7 +129,7 @@ func NewLicenseWindow(licenseTitle, licenseContents, promptText string) *License
133129 fmt .Fprint (v , promptText )
134130 }
135131
136- _ , err : = g .SetCurrentView ("license" )
132+ _ , err = g .SetCurrentView ("license" )
137133 if err != nil && err != gocui .ErrUnknownView {
138134 return err
139135 }
@@ -193,16 +189,32 @@ func NewLicenseWindow(licenseTitle, licenseContents, promptText string) *License
193189
194190// Helper to compute rectangles for license and prompt windows based on terminal size.
195191// Uses the same constants as LayoutManager (marginSize=1, promptWindowHeight=3).
196- func computeLicenseAndPromptRects (terminalWidth , terminalHeight int ) (lbx , lby , lex , ley , pbx , pby , pex , pey int ) {
192+ // computeLayoutRects consolidates rectangle computation and validation.
193+ // Returns rectangles for license and prompt windows or an error when the
194+ // terminal is too small.
195+ func computeLayoutRects (terminalWidth , terminalHeight int ) (lbx , lby , lex , ley , pbx , pby , pex , pey int , err error ) {
197196 marginSize := 1
198197 promptWindowHeight := 3
198+ const minTerminalWidth = 10
199+ const minTerminalHeight = 7
200+
201+ if terminalWidth < minTerminalWidth || terminalHeight < minTerminalHeight {
202+ err = fmt .Errorf ("increase window size to display license information and obtain user response to at least %dx%d" , minTerminalWidth , minTerminalHeight )
203+ return
204+ }
199205
200206 // License window dimensions
201207 lbx = marginSize
202208 lby = marginSize
203209 lex = terminalWidth - marginSize
204210 ley = terminalHeight - marginSize - promptWindowHeight
205211
212+ // Validate license rect (fallback guard – should not trigger if min constraints above are correct)
213+ if lbx >= lex || lby >= ley {
214+ err = fmt .Errorf ("increase window size to display prompt window and obtain user response to at least %dx%d" , minTerminalWidth , minTerminalHeight )
215+ return
216+ }
217+
206218 // Prompt window dimensions
207219 pbx = lbx
208220 pby = ley + marginSize
@@ -211,22 +223,6 @@ func computeLicenseAndPromptRects(terminalWidth, terminalHeight int) (lbx, lby,
211223 return
212224}
213225
214- // validateLicenseRect mirrors the guard used before creating the license view.
215- func validateLicenseRect (bx , by , ex , ey int ) error {
216- if bx >= ex || by >= ey {
217- return fmt .Errorf ("increase size of license window, currently (%d, %d, %d, %d), cannot obtain user response" , bx , by , ex , ey )
218- }
219- return nil
220- }
221-
222- // validatePromptRect mirrors the guard used before creating the prompt view.
223- func validatePromptRect (bx , by , ex , ey int ) error {
224- if bx >= ex || by >= ey {
225- return fmt .Errorf ("increase size of prompt window, currently (%d, %d, %d, %d)" , bx , by , ex , ey )
226- }
227- return nil
228- }
229-
230226func (l * LicenseWindowType ) Setup () error {
231227 log .Debug ("Setting up UI to display license" )
232228 g , err := gocui .NewGui (gocui .OutputNormal )
0 commit comments