Stream
Module to hold the stream classes.
- class StreamWriter(stream=<_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>, flush_on_write=True, theme=None)[source]
StreamWriter is a class that writes receives chunks of markdown text and renders them as ANSI formatted text before writing them to a stream. If a chunk cannot be rendered as ANSI formatted text, it is cached in a buffer and prepended to the next chunk.
Initialize the StreamWriter.
- Parameters:
stream – Output stream to write to. Defaults to sys.stdout.
flush_on_write – Whether to flush the stream after each successful
True. (write. Defaults to)
- close()[source]
Flush any remaining content and close the stream.
This method ensures all buffered content is written before closing.
- Return type:
- flush()[source]
Flush any remaining buffered content to the stream.
This method attempts to render any buffered markdown content. If rendering fails, the content is written as-is to the stream.
- Return type: