Skip to content

Fix Formatter BCE/HTML export and TerminalTimeoutError diagnostics #9

Closed

Description

@tony

Summary

Formatter in src/libvt/terminal.py (#2) drops background-color-erase (BCE) trailing spans in OutputFormat.VT and omits 16-color AnsiColor, 256-color IndexedColor, reverse, and text-decoration styles in OutputFormat.HTML, while AsyncTerminalStream.wait_for() in src/libvt/aio.py (#2) raises TerminalTimeoutError without parser_state or FlightRecorder tail bytes.

Reproduction

  1. Export a green-BCE EL 0 bar (CSI 42 m HI CSI K) through Formatter(OutputFormat.VT) and replay it into a second Terminal, and export an ANSI-colored row through Formatter(OutputFormat.HTML):
$ uv run python -c 'from libvt import Formatter, OutputFormat, Terminal; a = Terminal(rows=2, cols=10); a.feed(b"\x1b[42mHI\x1b[K\x1b[31;4m!"); vt_bytes = Formatter(OutputFormat.VT).format_terminal(a).encode(); b = Terminal(rows=2, cols=10); b.feed(vt_bytes); print("col5 bg after roundtrip:", b[0, 5].style.bg); print("html:", Formatter(OutputFormat.HTML).format_terminal(a))'

Expected

  • Replaying OutputFormat.VT output preserves AnsiColor.GREEN background across columns 2..9 (row.used), matching tmux capture-pane -e.
  • OutputFormat.HTML emits CSS color, background-color, reverse swap, and text-decoration rules for AnsiColor and IndexedColor in addition to RgbColor.
  • TerminalTimeoutError raised by wait_for() exposes structured attributes (parser_state, screen_text, recent_bytes) and includes parser_state (for example ParserState.OSC_STRING when a child hangs in an unterminated OSC sequence) plus recent FlightRecorder tail bytes in its message.

Actual

  • col5 bg after roundtrip: None because Formatter._format_vt() stops at limit = row.used if row.wrapped else row.text_used.
  • OutputFormat.HTML checks only isinstance(style.fg, RgbColor) and isinstance(style.bg, RgbColor), rendering 16-color and 256-color cells unstyled.
  • TerminalTimeoutError formats only terminal.text.
Environment
  • libvt: #2 (feat/v2-architecture, 0.1.0a0)
  • Python: 3.15.0 (unicodedata 17.0.0)
  • Reference tmux: 3.8a (tmux -f /dev/null)
  • OS: Linux x86_64

Proposal

Invariants

The invariants below are load-bearing; everything under Intent is open.

  • Feeding Formatter(OutputFormat.VT).format_snapshot(snap).encode() into a fresh Terminal of equal dimensions reproduces visible glyphs and cell Style attributes across 0..row.used - 1.
  • Formatter(OutputFormat.HTML) escapes text and restricts hyperlink schemes per Policy.allow_unsafe_uris while rendering AnsiColor, IndexedColor, RgbColor, reverse, bold, dim, italic, underline, strikethrough, and overline.
  • TerminalTimeoutError remains a subclass of both LibVtError and builtin TimeoutError.

Intent (non-binding)

  • Iterate up to row.used in _format_vt() so styled trailing blanks from EL / ED / ECH survive round-trips.
  • Resolve AnsiColor and IndexedColor through a standard 256-color palette table on Formatter (respecting Profile.fg_rgb / Profile.bg_rgb on reverse).
  • Attach parser_state: ParserState, screen_text: str, and recent_bytes: bytes to TerminalTimeoutError when recorder is present.

Not doing

  • Adding external CSS/HTML templating dependencies.

References

Activity

  1. added
    bug
    on Nov 22, 2026
  2. tony commented on Nov 23, 2026

    @tony
    MemberAuthor

    Resolved in #2 (0c7ee41).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions