Patchwork [bitbake-devel] knotty: Limit printed lines to terminal size

login
register
mail settings
Submitter Richard Purdie
Date May 12, 2013, 7:25 a.m.
Message ID <1368343500.21569.0.camel@ted>
Download mbox | patch
Permalink /patch/49773/
State New
Headers show

Comments

Richard Purdie - May 12, 2013, 7:25 a.m.
If you have a small terminal window with a large number of bitbake threads,
the scrollback output becomes corrupted since the footer is larger than
the height of the screen.

This patch ensures we limit the number of printed lines to match the
terminal height.

Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
---

Patch

diff --git a/bitbake/lib/bb/ui/knotty.py b/bitbake/lib/bb/ui/knotty.py
index 6ea7d86..c9323d9 100644
--- a/bitbake/lib/bb/ui/knotty.py
+++ b/bitbake/lib/bb/ui/knotty.py
@@ -102,13 +102,14 @@  class InteractConsoleLogFilter(logging.Filter):
 
 class TerminalFilter(object):
     columns = 80
+    lines = 25
 
     def sigwinch_handle(self, signum, frame):
-        self.columns = self.getTerminalColumns()
+        (self.lines, self.columns) = self.getTerminalSize()
         if self._sigwinch_default:
             self._sigwinch_default(signum, frame)
 
-    def getTerminalColumns(self):
+    def getTerminalSize(self):
         def ioctl_GWINSZ(fd):
             try:
                 cr = struct.unpack('hh', fcntl.ioctl(fd, self.termios.TIOCGWINSZ, '1234'))
@@ -128,7 +129,7 @@  class TerminalFilter(object):
                 cr = (env['LINES'], env['COLUMNS'])
             except:
                 cr = (25, 80)
-        return cr[1]
+        return cr
 
     def __init__(self, main, helper, console, format):
         self.main = main
@@ -167,7 +168,7 @@  class TerminalFilter(object):
                 signal.signal(signal.SIGWINCH, self.sigwinch_handle)
             except:
                 pass
-            self.columns = self.getTerminalColumns()
+            (self.lines, self.columns) = self.getTerminalSize()
         except:
             self.cuu = None
         console.addFilter(InteractConsoleLogFilter(self, format))
@@ -195,18 +196,30 @@  class TerminalFilter(object):
         for t in runningpids:
             tasks.append("%s (pid %s)" % (activetasks[t]["title"], t))
 
+        display = []
+        def addline(content, display):
+            display.append(content)
+            extra = int(len(content) / (self.columns + 1))
+            for n in range(extra):
+                display.append(None)
+            return 1 + extra
+
         if self.main.shutdown:
             content = "Waiting for %s running tasks to finish:" % len(activetasks)
         elif not len(activetasks):
             content = "No currently running tasks (%s of %s)" % (self.helper.tasknumber_current, self.helper.tasknumber_total)
         else:
             content = "Currently %s running tasks (%s of %s):" % (len(activetasks), self.helper.tasknumber_current, self.helper.tasknumber_total)
-        print(content)
-        lines = 1 + int(len(content) / (self.columns + 1))
+        lines = addline(content, display)
         for tasknum, task in enumerate(tasks):
             content = "%s: %s" % (tasknum, task)
-            print(content)
-            lines = lines + 1 + int(len(content) / (self.columns + 1))
+            lines = lines + addline(content, display)
+        if lines > (self.lines -1):
+            display = display[-(self.lines - 1):]
+            lines = self.lines - 1
+        for l in display:
+             if l:
+                print(l)
         self.footer_present = lines
         self.lastpids = runningpids[:]
         self.lastcount = self.helper.tasknumber_current