diff --git a/lixian_colors.py b/lixian_colors.py index 2c25ccb..2aaed13 100644 --- a/lixian_colors.py +++ b/lixian_colors.py @@ -40,6 +40,7 @@ def __enter__(self): softspace = get_softspace(sys.stdout) sys.stdout = console sys.stdout.softspace = softspace + return console def __exit__(self, type, value, traceback): softspace = get_softspace(sys.stdout) sys.stdout = self.stdout diff --git a/lixian_colors_console.py b/lixian_colors_console.py index e3e732d..dc217f7 100644 --- a/lixian_colors_console.py +++ b/lixian_colors_console.py @@ -49,5 +49,10 @@ def write(self, s): else: raise def flush(self, *args): - self.output.flush(*args) - + try: + self.output.flush(*args) + except IOError as e: + if e.errno == errno.EPIPE: + sys.exit(141) + else: + raise diff --git a/lixian_commands/util.py b/lixian_commands/util.py index e100cbc..a6a5fa3 100644 --- a/lixian_commands/util.py +++ b/lixian_commands/util.py @@ -68,7 +68,7 @@ def output_tasks(tasks, columns, args, top=True): 'failed':'red', } c = status_colors[t['status_text']] - with colors(args.colors).ansi(c)(): + with colors(args.colors).ansi(c)() as output: for k in columns: if k == 'n': if top: @@ -103,6 +103,7 @@ def output_tasks(tasks, columns, args, top=True): else: raise NotImplementedError(k) print + output.flush() def usage(doc=lixian_help.usage, message=None): if hasattr(doc, '__call__'):