All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] knotty: Limit printed lines to terminal size
@ 2013-05-12  7:25 Richard Purdie
  0 siblings, 0 replies; only message in thread
From: Richard Purdie @ 2013-05-12  7:25 UTC (permalink / raw)
  To: bitbake-devel

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>
---
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





^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2013-05-12  7:43 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-05-12  7:25 [PATCH] knotty: Limit printed lines to terminal size Richard Purdie

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.