histedit: notice when the main window underflows height and abort
authorAugie Fackler <augie@google.com>
Fri, 22 Jan 2021 15:32:00 -0500
changeset 46395 a936e570288d
parent 46394 8477c91b5e8e
child 46396 11ce2977572f
histedit: notice when the main window underflows height and abort If you try to have a 13-line-tall terminal and use curses histedit, it fails by spinning in an infinite loop due to the catch-all ignore of curses errors on line 1682 of histedit.py. We should also fix that catch-all ignore of curses errors (what other demons lurk here, I wonder?) but we can trivially catch this case and guide the user to a happy path. We've seen this mostly in IDE users that have a tendency to have really tiny embedded terminal windows. Differential Revision: https://phab.mercurial-scm.org/D9854
hgext/histedit.py
--- a/hgext/histedit.py	Fri Jan 22 15:29:12 2021 -0500
+++ b/hgext/histedit.py	Fri Jan 22 15:32:00 2021 -0500
@@ -1581,10 +1581,19 @@
     def layout(mode):
         maxy, maxx = stdscr.getmaxyx()
         helplen = len(helplines(mode))
+        mainlen = maxy - helplen - 12
+        if mainlen < 1:
+            raise error.Abort(
+                _(b"terminal dimensions %d by %d too small for curses histedit")
+                % (maxy, maxx),
+                hint=_(
+                    b"enlarge your terminal or use --config ui.interface=text"
+                ),
+            )
         return {
             b'commit': (12, maxx),
             b'help': (helplen, maxx),
-            b'main': (maxy - helplen - 12, maxx),
+            b'main': (mainlen, maxx),
         }
 
     def drawvertwin(size, y, x):