@@ -106,18 +106,12 @@ func NewLicenseWindow(licenseTitle, licenseContents, promptText string) *License
106106 licenseWindow .LayoutManager = func (g * gocui.Gui ) error {
107107 terminalWidth , terminalHeight := g .Size ()
108108
109- marginSize := 1
110- promptWindowHeight := 3
111-
112- // License window dimensions
113- licenseWindowBeginX := marginSize
114- licenseWindowBeginY := marginSize
115- licenseWindowEndX := terminalWidth - marginSize
116- licenseWindowEndY := terminalHeight - marginSize - promptWindowHeight
117- if licenseWindowBeginX >= licenseWindowEndX || licenseWindowBeginY >= licenseWindowEndY {
118- return fmt .Errorf ("increase size of license window, currently (%d, %d, %d, %d), cannot obtain user response" , licenseWindowBeginX , licenseWindowBeginY , licenseWindowEndX , licenseWindowEndY )
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 {
112+ return err
119113 }
120- if v , err := g .SetView ("license" , licenseWindowBeginX , licenseWindowBeginY , licenseWindowEndX , licenseWindowEndY ); err != nil {
114+ if v , err := g .SetView ("license" , lbx , lby , lex , ley ); err != nil {
121115 if err != gocui .ErrUnknownView {
122116 log .Error ("Cannot modify license window: " , err )
123117 return err
@@ -128,14 +122,10 @@ func NewLicenseWindow(licenseTitle, licenseContents, promptText string) *License
128122 }
129123
130124 // Prompt window dimensions
131- promptWindowBeginX := licenseWindowBeginX
132- promptWindowBeginY := licenseWindowEndY + marginSize
133- promptWindowEndX := licenseWindowEndX
134- promptWindowEndY := terminalHeight - marginSize
135- if promptWindowBeginX >= promptWindowEndX || promptWindowBeginY >= promptWindowEndY {
136- return fmt .Errorf ("increase size of prompt window, currently (%d, %d, %d, %d)" , promptWindowBeginX , promptWindowBeginY , promptWindowEndX , promptWindowEndY )
125+ if err := validatePromptRect (pbx , pby , pex , pey ); err != nil {
126+ return err
137127 }
138- if v , err := g .SetView ("prompt" , promptWindowBeginX , promptWindowBeginY , promptWindowEndX , promptWindowEndY ); err != nil {
128+ if v , err := g .SetView ("prompt" , pbx , pby , pex , pey ); err != nil {
139129 if err != gocui .ErrUnknownView {
140130 log .Error ("Cannot modify prompt window: " , err )
141131 return err
@@ -201,6 +191,42 @@ func NewLicenseWindow(licenseTitle, licenseContents, promptText string) *License
201191 return licenseWindow
202192}
203193
194+ // Helper to compute rectangles for license and prompt windows based on terminal size.
195+ // 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 ) {
197+ marginSize := 1
198+ promptWindowHeight := 3
199+
200+ // License window dimensions
201+ lbx = marginSize
202+ lby = marginSize
203+ lex = terminalWidth - marginSize
204+ ley = terminalHeight - marginSize - promptWindowHeight
205+
206+ // Prompt window dimensions
207+ pbx = lbx
208+ pby = ley + marginSize
209+ pex = lex
210+ pey = terminalHeight - marginSize
211+ return
212+ }
213+
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+
204230func (l * LicenseWindowType ) Setup () error {
205231 log .Debug ("Setting up UI to display license" )
206232 g , err := gocui .NewGui (gocui .OutputNormal )
0 commit comments