API Reference
ANSI terminal emulation and conversion library.
The main entry point is Terminal.
- class ANSIParser(terminal: Terminal, warn_unknown: bool = False)[source]
Parser for ANSI control characters and escape sequences.
- class AnsiConverter(esc_char: str = '\x1b')[source]
Converter to compact ANSI-encoded text output.
- convert(screen: ScreenBuffer) str[source]
Convert the full screen + history into a serialized output format.
- class Character(text: str = ' ', style: CharacterStyle = CharacterStyle(bold=False, dim=False, italic=False, underline=False, blink=False, reverse=False, hidden=False, strike=False, foreground=None, background=None), width: int = 1, continuation: bool = False)[source]
A single terminal cell character plus formatting state.
- class CharacterStyle(bold: bool = False, dim: bool = False, italic: bool = False, underline: bool = False, blink: bool = False, reverse: bool = False, hidden: bool = False, strike: bool = False, foreground: str | None = None, background: str | None = None)[source]
A complete style state for one terminal cell.
- with_updates(**kwargs: object) CharacterStyle[source]
Return a copied style with updated fields.
- class Converter[source]
Base class for terminal state converters.
- abstractmethod convert(screen: ScreenBuffer) str[source]
Convert the full screen + history into a serialized output format.
- class Cursor(x: int = 0, y: int = 0, style: CharacterStyle = CharacterStyle(bold=False, dim=False, italic=False, underline=False, blink=False, reverse=False, hidden=False, strike=False, foreground=None, background=None), visible: bool = True)[source]
The active cursor and style state.
- class HtmlConverter(class_prefix: str = 'erbsland-ansi')[source]
Converter to compact HTML using reusable CSS classes.
- convert(screen: ScreenBuffer) str[source]
Convert the full screen + history into a serialized output format.
- class ScreenBuffer(width: int, height: int, back_buffer_height: int)[source]
A visible screen with an attached scroll-back buffer.
- scroll_up(lines: int = 1) None[source]
Scroll visible content up and append blank lines at the bottom.
- set_character(x: int, y: int, character: str, style: CharacterStyle, width: int = 1) None[source]
Write one character at the given visible coordinates.
- append_combining(x: int, y: int, combining_mark: str) None[source]
Append a combining mark to the base cell at the given coordinates.
- class Terminal(width: int = 120, height: int = 40, back_buffer_height: int = 2000, warn_unknown_sequences: bool = False)[source]
ANSI terminal emulator with scroll-back history and converters.
- property screen: ScreenBuffer
Return the currently active screen buffer.
- write(data: str, collapse_capture_updates: bool = False) None[source]
Process terminal output text including ANSI escape sequences.
- Parameters:
data – Terminal output text.
collapse_capture_updates – Apply a heuristic for text captures where carriage returns were normalized to newlines.
- writeFile(capture_file: str | Path, encoding: str = 'utf-8', errors: str = 'replace', collapse_capture_updates: bool | None = None) None[source]
Read and process terminal output from a capture file.
The file is read as bytes to preserve raw carriage returns. If the capture appears to be a transcript with CR-only line endings (for example from script), it is normalized to newlines automatically.
- Parameters:
capture_file – Path to the capture file.
encoding – Encoding used to decode bytes into text.
errors – Decoder error handling strategy.
collapse_capture_updates – Optional heuristic to collapse progress update lines when CR was normalized before parsing. If omitted, auto-detection is used for transcript-style captures.
- to_ansi(esc_char: str = '\x1b') str[source]
Convert current screen + history to compact ANSI encoded text.
- to_html(class_prefix: str = 'erbsland-ansi') str[source]
Convert current screen + history to compact HTML.
- move_cursor_to(x: int, y: int) None[source]
Move cursor to an absolute position within visible screen bounds.
- class TextConverter[source]
Converter to plain text with all ANSI formatting removed.
- convert(screen: ScreenBuffer) str[source]
Convert the full screen + history into a serialized output format.