libvt.views¶
Read-only cursor, cell, row, history, and rectangular region views.
-
class libvt.views.Cell¶class libvt.views.Cell¶
Bases:
objectImmutable view of a single terminal grid cell.
Examples
>>> term = Terminal(rows=1, cols=8) >>> term.feed("\x1b[1;32m日\x1b[0mok".encode()) >>> snap = term.committed >>> snap[0, 0].text, snap[0, 0].width, snap[0, 0].style.bold ('日', 2, True) >>> snap[0, 1].width_role.name, snap[0, 1].width ('SPACER_TAIL', 0)
-
class libvt.views.CursorShape¶class libvt.views.CursorShape¶
Bases:
StrEnumCursor glyph shape configured via
DECSCUSR(CSI Ps SP q).
-
class libvt.views.RegionView¶class libvt.views.RegionView¶
Read-only 2D rectangular slice view over
(rows, cols).A live region resolves its selected viewport coordinates from the live
Screenon each read, staying aligned across scrolls, reflows, and resizes while clipping to the current dimensions. Regions from a snapshot or its viewport keep the rows and geometry captured with the frame.Examples
>>> from libvt.testing import serialize_vt_snapshot >>> term = Terminal(rows=3, cols=10) >>> term.feed(b"header\r\n\x1b[1mitem 1\x1b[0m\r\nitem 2") >>> region = term.committed[1:3, 0:6] >>> print(serialize_vt_snapshot(region)) size=6x2 region=True ┌──────┐ │item 1│ │item 2│ └──────┘ styles: r0[0..6]: bold
-
class libvt.views.RowRun¶class libvt.views.RowRun¶
Examples
>>> term = Terminal(rows=1, cols=12) >>> term.feed(b"\x1b[1;32mPASS\x1b[0m test") >>> [(r.start_col, r.end_col, r.text, r.style.bold) for r in term.committed[0].runs] [(0, 4, 'PASS', True), (4, 10, ' test', False)]
-
class libvt.views.RowView¶class libvt.views.RowView¶
Read-only sequence view over one live viewport or scrollback row.
A live row resolves its viewport row index on each read and clips to the live screen dimensions, appearing empty while the screen is shorter than its row index. A slice retains its selected columns and clips them to the live width. Frozen rows keep their captured width.
Examples
>>> term = Terminal(rows=2, cols=8) >>> term.feed(b"long_line") >>> row0 = term.committed[0] >>> row0.text, row0.wrapped, len(row0) ('long_lin', True, 8)
-
class libvt.views.ScrollRegion¶class libvt.views.ScrollRegion¶
Bases:
objectInclusive zero-based scroll margin bounds (
DECSTBM/DECSLRM).
-
libvt.views.format_rows_text(rows, *, unwrap=False)¶libvt.views.format_rows_text(rows, *, unwrap=False)¶
Format rows as newline-joined text omitting trailing blank lines.
- Parameters:
rows (
collections.abc.Sequence[RowLike]) – Viewport or scrollback rows to format.unwrap (
bool) – WhenTrue, join contiguousrow.wrappedcontinuation rows onto the same logical line without inserting"\n".
- Returns:
Rendered text with trailing blank lines omitted.
- Return type:
Examples
>>> term = Terminal(rows=2, cols=8) >>> term.feed(b"hello world") >>> term.screen.text, term.screen.unwrapped_text ('hello wo\nrld', 'hello world')