Pārlūkot izejas kodu

Prevent a crash bug when shrinking the screen below 1/2 the length of the help string

Chris Rose 14 gadi atpakaļ
vecāks
revīzija
3781edb034
1 mainītis faili ar 17 papildinājumiem un 2 dzēšanām
  1. 17 2
      celery/events/cursesmon.py

+ 17 - 2
celery/events/cursesmon.py

@@ -76,6 +76,16 @@ class CursesMonitor(object):
             self.screen_width = len(row[:mx])
         return row[:mx]
 
+    @property
+    def screen_width(self):
+        _, mx = self.win.getmaxyx()
+        return mx
+
+    @property
+    def screen_height(self):
+        my, _ = self.win.getmaxyx()
+        return my
+
     @property
     def display_width(self):
         _, mx = self.win.getmaxyx()
@@ -376,10 +386,15 @@ class CursesMonitor(object):
                 curses.A_DIM)
 
         # Help
-        win.addstr(my - 2, x, self.help_title, curses.A_BOLD)
-        win.addstr(my - 2, x + len(self.help_title), self.help, curses.A_DIM)
+        self.safe_add_str(my - 2, x, self.help_title, curses.A_BOLD)
+        self.safe_add_str(my - 2, x + len(self.help_title), self.help, curses.A_DIM)
         win.refresh()
 
+    def safe_add_str(self, y, x, string, *args, **kwargs):
+        if x + len(string) > self.screen_width:
+            string = string[:self.screen_width - x]
+        self.win.addstr(y, x, string, *args, **kwargs)
+
     def init_screen(self):
         self.win = curses.initscr()
         self.win.nodelay(True)