]> git.ipfire.org Git - thirdparty/openembedded/openembedded-core-contrib.git/commitdiff
knotty/msg: Avoid usage of curses initscr/endwin to avoid terminal corruption
authorRichard Purdie <richard.purdie@linuxfoundation.org>
Sun, 25 Nov 2012 21:17:41 +0000 (21:17 +0000)
committerRichard Purdie <richard.purdie@linuxfoundation.org>
Sun, 25 Nov 2012 21:34:36 +0000 (21:34 +0000)
Using curses initscr/endwin causes screen corruption if for example you
suspend bitbake and resume it. This changes the code to use a less
invasive approach to determining colour availability on the terminal.

Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
lib/bb/msg.py
lib/bb/ui/knotty.py

index 007c95a4eaaebe3c65647b99a97058e9a320b13b..e70daee92f38f4f4613959fdcd266d208ceb1b11 100644 (file)
@@ -106,17 +106,7 @@ class BBLogFormatter(logging.Formatter):
         return record
 
     def enable_color(self):
-        import curses
-        try:
-            win = None
-            win = curses.initscr()
-            if curses.has_colors():
-                self.color_enabled = True
-        except:
-            pass
-        finally:
-            if win is not None:
-                curses.endwin()
+        self.color_enabled = True
 
 class BBLogFilter(object):
     def __init__(self, handler, level, debug_domains):
index a63d8b120e16fec55dc019e1d9aed6dd78d24e96..be63e730f099e1d5d5d79f046f0a54c04a7977ae 100644 (file)
@@ -157,6 +157,8 @@ class TerminalFilter(object):
             new[3] = new[3] & ~termios.ECHO
             termios.tcsetattr(fd, termios.TCSADRAIN, new)
             curses.setupterm()
+            if curses.tigetnum("colors") > 2:
+                format.enable_color()
             self.ed = curses.tigetstr("ed")
             if self.ed:
                 self.cuu = curses.tigetstr("cuu")
@@ -240,17 +242,15 @@ def main(server, eventHandler, tf = TerminalFilter):
     console = logging.StreamHandler(sys.stdout)
     format_str = "%(levelname)s: %(message)s"
     format = bb.msg.BBLogFormatter(format_str)
-    if interactive:
-        format.enable_color()
     bb.msg.addDefaultlogFilter(console)
     console.setFormatter(format)
     logger.addHandler(console)
     if consolelogfile:
         bb.utils.mkdirhier(os.path.dirname(consolelogfile))
-        format = bb.msg.BBLogFormatter(format_str)
+        conlogformat = bb.msg.BBLogFormatter(format_str)
         consolelog = logging.FileHandler(consolelogfile)
         bb.msg.addDefaultlogFilter(consolelog)
-        consolelog.setFormatter(format)
+        consolelog.setFormatter(conlogformat)
         logger.addHandler(consolelog)
 
     try: