def output(self, text, highlighter=None):
"""Send text to the environment's output stream.
:param text: the text to output
:param highlighter: an optional function to colourize the text
"""
if not self.has_pipe: # only colourize when the output is not piped
highlighter = highlighter or (lambda x: x)
text = highlighter(text)
output = "{}\n".format(text)
if isinstance(self.output_stream, io.BufferedIOBase):
output = bytes(output, encoding='utf-8')
self.output_stream.write(output)
self.output_stream.flush()
评论列表
文章目录