From 93473a0c427ab37d795d400a46e36dac30f0eeab Mon Sep 17 00:00:00 2001 From: Martinez Date: Fri, 21 Oct 2016 10:14:58 +0200 Subject: [PATCH] add over.text.Output.add_sink, little api breakage --- over/text.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/over/text.py b/over/text.py index c4e312c..ddadaad 100644 --- a/over/text.py +++ b/over/text.py @@ -326,19 +326,22 @@ class Output: def __init__(self, name, format="[%Y-%m-%d %H:%M:%S %Z] <@> -- , ", colors=True, end=".\n", indent=True, stream=sys.stderr): self.name = name self.format = format - self.colors = colors and stream.isatty() self.end = end self.indent = indent - self.stream = stream + self.sinks = [] + + self.add_sink(stream, colors and stream.isatty()) - def write(self, text, tag=None, format=None, colors=None, end=None): + def add_sink(self, stream, colors): + self.sinks.append((stream, colors)) + + def write(self, text, tag=None, format=None, end=None): """ @while displaying text """ tag = tag or self.__class__.tag.long.info format = format or self.format - colors = colors or self.colors end = end or self.end output = datetime.datetime.now(tzlocal.get_localzone()).strftime(format) @@ -353,8 +356,9 @@ class Output: output = output.replace("", text) output += end - self.stream.write(render(output, colors)) - self.stream.flush() + for sink, colors in self.sinks: + sink.write(render(output, colors)) + sink.flush() def flush(self): """