add over.text.Output.add_sink, little api breakage

This commit is contained in:
Martinez 2016-10-21 10:14:58 +02:00
parent 6b518e8ddc
commit 93473a0c42

View file

@ -326,19 +326,22 @@ class Output:
def __init__(self, name, format="[%Y-%m-%d %H:%M:%S %Z] <@> -- <n>, <i><t>", colors=True, end=".\n", indent=True, stream=sys.stderr): def __init__(self, name, format="[%Y-%m-%d %H:%M:%S %Z] <@> -- <n>, <i><t>", colors=True, end=".\n", indent=True, stream=sys.stderr):
self.name = name self.name = name
self.format = format self.format = format
self.colors = colors and stream.isatty()
self.end = end self.end = end
self.indent = indent 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 @while displaying text
""" """
tag = tag or self.__class__.tag.long.info tag = tag or self.__class__.tag.long.info
format = format or self.format format = format or self.format
colors = colors or self.colors
end = end or self.end end = end or self.end
output = datetime.datetime.now(tzlocal.get_localzone()).strftime(format) output = datetime.datetime.now(tzlocal.get_localzone()).strftime(format)
@ -353,8 +356,9 @@ class Output:
output = output.replace("<t>", text) output = output.replace("<t>", text)
output += end output += end
self.stream.write(render(output, colors)) for sink, colors in self.sinks:
self.stream.flush() sink.write(render(output, colors))
sink.flush()
def flush(self): def flush(self):
""" """