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): """