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:

None

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:

None

write_line(line)[source]

Write a line of unformatted text to the stream.

Return type:

None

write_markdown_chunk(chunk)[source]

Write a chunk of markdown text to the stream.

If the chunk cannot be rendered as ANSI formatted text, it is cached in the buffer and prepended to the next chunk for retry.

Return type:

None

Parameters:

chunk – A piece of markdown content to format and write.