add over.text.Output.add_sink, little api breakage
This commit is contained in:
parent
6b518e8ddc
commit
93473a0c42
1 changed files with 10 additions and 6 deletions
16
over/text.py
16
over/text.py
|
@ -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):
|
||||
self.name = name
|
||||
self.format = format
|
||||
self.colors = colors and stream.isatty()
|
||||
self.end = end
|
||||
self.indent = indent
|
||||
self.stream = stream
|
||||
self.sinks = []
|
||||
|
||||
def write(self, text, tag=None, format=None, colors=None, end=None):
|
||||
self.add_sink(stream, colors and stream.isatty())
|
||||
|
||||
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("<t>", 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):
|
||||
"""
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue