libvt.screen¶
Screen and ScreenSet grid state. Compatibility re-exports for cell, cursor,
row, and region views live in libvt.views.
Zero-based screen buffer, dual primary/alternate screens, and resize.
Bases:
objectMutable 2D character grid with
FrozenRowRLE scrollback and reflow.Examples
>>> term = Terminal(rows=2, cols=10) >>> term.feed(b"line 1\r\nline 2\r\nline 3") >>> term.screen.lines, [r.text for r in term.screen.history] (('line 2', 'line 3'), ['line 1'])
-
__init__(*, rows=24, cols=80, scrollback=2000, keyboard_stack_depth=8, cell_height_px=16, max_images=256, max_placements=1024, max_image_dimension=10000, is_alt=False, top_margin_scrolls_to_history=False, profile=¶
DEFAULT_PROFILE, on_mutate=None)method[source]method[source]__init__(*, rows=24, cols=80, scrollback=2000, keyboard_stack_depth=8, cell_height_px=16, max_images=256, max_placements=1024, max_image_dimension=10000, is_alt=False, top_margin_scrolls_to_history=False, profile=¶DEFAULT_PROFILE, on_mutate=None)
Return
Profilegoverning width and grid behavior.
Return
Truewhen this screen is an alternate screen buffer.
Return cumulative primary rows scrolled off the top margin.
Return
O(1)immutableRowViewsequence over scrollback.
Return sorted horizontal tabstop columns.
Return
XTMODKEYSmodifyOtherKeyslevel (0,1, or2).
Set a horizontal tabstop at col (
HTS).
Remove the horizontal tabstop at col (
TBC 0).
Remove all horizontal tabstops (
TBC 3).- Return type:
Clear all sealed scrollback rows (
ED 3).- Return type:
Lazily create and return this screen’s graphics tracker.
- Return type:
Return stored
SIXEL/ KittyImageMetarecords.
Repair cross-row
SPACER_HEADpairs before mutating cells.
Clear preceding
SPACER_HEADandwrappedif(row, 0)splits.
Return right-trimmed text for every visible row.
Return space-padded text of width
colsfor every visible row.
Return visible screen text with trailing blank rows omitted.
Return visible screen text with soft-wrapped rows joined.
Contiguous
row.wrappedrows join without"\n"while hard linebreaks stay"\n"and trailing blank rows are omitted.Examples
>>> term = Terminal(rows=3, cols=8) >>> term.feed(b"hello world\r\nok") >>> term.screen.unwrapped_text 'hello world\nok'
Push active lines up to last non-blank row into history.
Resize screen to
(rows, cols), optionally reflowing soft wraps.
Clear all visible rows, margins, cursor, keyboard stack, and tabstops.
- Return type:
Copy a rectangular 2D cell region from source onto this screen.
Copies packed 64-bit SGR attributes, grapheme strings,
WidthRole,OSC 8hyperlinks, andDECSCAprotection without re-encoding ANSI sequences. Out-of-bounds source or destination coordinates clip cleanly, split wide glyphs heal to narrow blanks at clip boundaries, and sourceSPACER_HEADsoft-wrap markers convert to narrow blanks. Rows overwritten up tocolsclearwrappedunless preserve_wrap isTrueon a full-width copy.- Parameters:
source (
Snapshot|Screen|RegionView) – Source grid surface to copy cells from.top (
int, default 0) – Destination zero-based top row offset (negative values clip).left (
int, default 0) – Destination zero-based left column offset (negative values clip).src_top (
int, default 0) – Source zero-based starting row offset.src_left (
int, default 0) – Source zero-based starting column offset.rows (
int|None,optional) – Maximum row count to copy;Nonecopiessource.rows - src_top.cols (
int|None,optional) – Maximum column count to copy;Nonecopiessource.cols - src_left.preserve_wrap (
bool, default False) – Preserve sourcewrappedflags when blitting full-width rows (dst_col == 0andwidth == self.cols == source_row.cols).
- Return type:
Examples
>>> from libvt.screen import Screen >>> from libvt.terminal import Terminal >>> pane = Terminal(rows=2, cols=6) >>> pane.feed("日本!\r\nok".encode()) >>> canvas = Screen(rows=3, cols=10) >>> canvas.blit(pane.committed, top=1, left=2) >>> canvas.lines ('', ' 日本!', ' ok')
Write display-width-aware text onto row starting at col.
Places narrow, wide, and combining grapheme clusters on a single row without moving
cursoror settingwrapped, clipping negative col offsets and healing split wide cells at start and end boundaries.- Parameters:
row (
int) – Zero-based destination row index (out-of-range values return0).col (
int) – Zero-based starting column index (negative values left-clip).text (
str) – Text to draw; control characters are skipped and wide clusters stop before overflowingmax_colsorcols.style (
Style, default DEFAULT_STYLE) – Cell SGR rendition applied to written clusters.hyperlink (
Hyperlink|None,optional) –OSC 8hyperlink attached to written cells.protected (
bool, default False) –DECSCAcharacter-protection flag respected byDECSEDandDECSEL.max_cols (
int|None,optional) – Maximum display columns to examine from col;Nonewrites up tocols - col.profile (
Profile|None,optional) – Compatibility profile used for grapheme display width; defaults to this screen’s profile.
- Returns:
Number of visible destination columns written on
0..cols.- Return type:
Examples
>>> from libvt.screen import Screen >>> from libvt.style import AnsiColor, Style >>> scr = Screen(rows=1, cols=8) >>> scr.put_text(0, 1, "日本ok", style=Style(fg=AnsiColor.GREEN), max_cols=5) 5 >>> scr.lines, scr[0, 1].style.fg ((' 日本o',), <AnsiColor.GREEN: 2>)
Freeze this screen into an immutable
Snapshot.Clones visible viewport rows and CoW scrollback blocks so subsequent edits on this
Screennever mutate the returned snapshot.- Parameters:
cursor (
Cursor|None,optional) – Explicit cursor state for the snapshot; defaults tocursor.title (
str, default “”) – Window title metadata stored on the snapshot.cwd (
str, default “”) – Working directory path stored on the snapshot.cwd_uri (
str, default “”) – RawOSC 7/OSC 9;9working directory URI.modes (
frozenset[Mode],optional) – Enabled ANSI and DEC private modes stored on the snapshot.active_is_alt (
bool, default False) – Whether the snapshot marks the alternate screen active (omitting primary scrollback whenTrue).appearance (
Appearance|None,optional) – Theme scheme, default RGBs, palette overrides, and reverse-video state; inferred from modes whenNone.program_status (
ProgramStatus|None,optional) – Highest-urgencyOSC 7501/OSC 9;4status record.program_statuses (
Mapping[str,ProgramStatus] |None,optional) – ActiveOSC 7501task records keyed byid.generation (
int|None,optional) – Explicit generation watermark; defaults to the row mutation counter.profile (
Profile|None,optional) – Terminal compatibility profile stored on the snapshot; defaults to this screen’s profile.
- Returns:
Point-in-time immutable screen capture.
- Return type:
Examples
>>> from libvt.screen import Cursor, Screen >>> scr = Screen(rows=2, cols=8) >>> _ = scr.put_text(0, 0, "ready") >>> snap = scr.snapshot(cursor=Cursor(row=0, col=5)) >>> _ = scr.put_text(0, 0, "later") >>> snap.lines, (snap.cursor.row, snap.cursor.col) (('ready', ''), (0, 5))
-
Bases:
objectDual primary and alternate (
?1049) screen pair.-
__init__(*, rows=24, cols=80, scrollback=2000, keyboard_stack_depth=8, cell_height_px=16, max_images=256, max_placements=1024, max_image_dimension=10000, top_margin_scrolls_to_history=False, profile=¶
DEFAULT_PROFILE, on_mutate=None)method[source]method[source]__init__(*, rows=24, cols=80, scrollback=2000, keyboard_stack_depth=8, cell_height_px=16, max_images=256, max_placements=1024, max_image_dimension=10000, top_margin_scrolls_to_history=False, profile=¶DEFAULT_PROFILE, on_mutate=None)
Return
Truewhen the alternate screen is active.
Return the currently active
Screen.
-