bitbake: knotty/msg: Avoid usage of curses initscr/endwin to avoid terminal corruption
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. (Bitbake rev: 4548a8f037eaf8d47a77052acc3e9ec264ac41e0) Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
parent
8a3dd9e908
commit
9be83df144
|
@ -106,17 +106,7 @@ class BBLogFormatter(logging.Formatter):
|
||||||
return record
|
return record
|
||||||
|
|
||||||
def enable_color(self):
|
def enable_color(self):
|
||||||
import curses
|
self.color_enabled = True
|
||||||
try:
|
|
||||||
win = None
|
|
||||||
win = curses.initscr()
|
|
||||||
if curses.has_colors():
|
|
||||||
self.color_enabled = True
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
finally:
|
|
||||||
if win is not None:
|
|
||||||
curses.endwin()
|
|
||||||
|
|
||||||
class BBLogFilter(object):
|
class BBLogFilter(object):
|
||||||
def __init__(self, handler, level, debug_domains):
|
def __init__(self, handler, level, debug_domains):
|
||||||
|
|
|
@ -157,6 +157,8 @@ class TerminalFilter(object):
|
||||||
new[3] = new[3] & ~termios.ECHO
|
new[3] = new[3] & ~termios.ECHO
|
||||||
termios.tcsetattr(fd, termios.TCSADRAIN, new)
|
termios.tcsetattr(fd, termios.TCSADRAIN, new)
|
||||||
curses.setupterm()
|
curses.setupterm()
|
||||||
|
if curses.tigetnum("colors") > 2:
|
||||||
|
format.enable_color()
|
||||||
self.ed = curses.tigetstr("ed")
|
self.ed = curses.tigetstr("ed")
|
||||||
if self.ed:
|
if self.ed:
|
||||||
self.cuu = curses.tigetstr("cuu")
|
self.cuu = curses.tigetstr("cuu")
|
||||||
|
@ -240,17 +242,15 @@ def main(server, eventHandler, tf = TerminalFilter):
|
||||||
console = logging.StreamHandler(sys.stdout)
|
console = logging.StreamHandler(sys.stdout)
|
||||||
format_str = "%(levelname)s: %(message)s"
|
format_str = "%(levelname)s: %(message)s"
|
||||||
format = bb.msg.BBLogFormatter(format_str)
|
format = bb.msg.BBLogFormatter(format_str)
|
||||||
if interactive:
|
|
||||||
format.enable_color()
|
|
||||||
bb.msg.addDefaultlogFilter(console)
|
bb.msg.addDefaultlogFilter(console)
|
||||||
console.setFormatter(format)
|
console.setFormatter(format)
|
||||||
logger.addHandler(console)
|
logger.addHandler(console)
|
||||||
if consolelogfile:
|
if consolelogfile:
|
||||||
bb.utils.mkdirhier(os.path.dirname(consolelogfile))
|
bb.utils.mkdirhier(os.path.dirname(consolelogfile))
|
||||||
format = bb.msg.BBLogFormatter(format_str)
|
conlogformat = bb.msg.BBLogFormatter(format_str)
|
||||||
consolelog = logging.FileHandler(consolelogfile)
|
consolelog = logging.FileHandler(consolelogfile)
|
||||||
bb.msg.addDefaultlogFilter(consolelog)
|
bb.msg.addDefaultlogFilter(consolelog)
|
||||||
consolelog.setFormatter(format)
|
consolelog.setFormatter(conlogformat)
|
||||||
logger.addHandler(consolelog)
|
logger.addHandler(consolelog)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
Loading…
Reference in New Issue