Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ returned by {meth}`~libvt.snapshot.Snapshot.to_dict`.

### Fixes

#### Reduce full-display erase overhead (#199)

Full-row display erases (`ED 0`, `ED 1`, `ED 2`, and `ED 22`) and `DECCOLM`
clears on {class}`~libvt.terminal.Terminal` now check incoming wrap boundaries
once per erased span rather than per cleared row. `DECCOLM` clears also sever
incoming scrollback wraps when clearing the display.

#### Reject attribute deletion on snapshots (#198)

Deleting an attribute on {class}`~libvt.snapshot.Snapshot` now raises
Expand Down
35 changes: 35 additions & 0 deletions src/libvt/screen.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
)

if t.TYPE_CHECKING:
from libvt._grid import _CellExt
from libvt.graphics import GraphicsTracker, ImageMeta, ImagePlacement


Expand Down Expand Up @@ -307,6 +308,40 @@ def _sever_incoming_wrap(
self._clear_row_spacer_head(prev)
prev.wrapped = False

def _clear_rows(
self,
start: int,
stop: int,
bce_word: int,
bce_ext: _CellExt | None,
*,
selective: bool = False,
sever_boundary: bool = True,
) -> None:
"""Clear full viewport rows ``[start, stop)`` with boundary wrap handling.

When ``sever_boundary`` is ``True``, check and sever an incoming wrap
from the row before ``start`` (or scrollback when ``start == 0``).
Pass ``sever_boundary=False`` only when the caller already cleared the
predecessor's wrap link; selective erases still check internal rows
``idx > start`` because protected cells may keep a prior row wrapped.
"""
if start >= stop:
return
rows = self._rows
cols = self._cols
if not selective:
if sever_boundary:
self._sever_incoming_wrap(start)
target_rows = rows if start == 0 and stop == len(rows) else rows[start:stop]
for row_obj in target_rows:
row_obj.reset_blank(cols, bce_word, bce_ext)
return
for idx in range(start, stop):
if sever_boundary or idx > start:
self._sever_incoming_wrap(idx, selective=True)
rows[idx].clear_range(0, cols, bce_word, bce_ext, selective=True)

def _heal_before_erase(
self, row: int, start: int, end: int, *, selective: bool
) -> None:
Expand Down
35 changes: 17 additions & 18 deletions src/libvt/terminal.py
Original file line number Diff line number Diff line change
Expand Up @@ -3492,9 +3492,7 @@ def _apply_deccolm(self, *, enabled: bool) -> None:
)
if not self._modes.is_set(Mode.DECNCSM):
bce_w, bce_e = self._bce_pair()
for r in range(scr.rows):
scr._rows[r].clear_range(0, scr.cols, bce_w, bce_e)
scr._rows[r].wrapped = False
scr._clear_rows(0, scr.rows, bce_w, bce_e)
if scr._gfx is not None:
scr._gfx.clear_active_screen(scr._scrolled_total, scr.rows)
self._notify_erase(Rect(0, 0, scr.rows, scr.cols), EraseCause.ED)
Expand Down Expand Up @@ -3661,7 +3659,8 @@ def _erase_display(

if mode == 0:
if not phantom:
scr._sever_incoming_wrap(c_row, start=c_col, selective=selective)
if c_col <= 1:
scr._sever_incoming_wrap(c_row, start=c_col, selective=selective)
scr._heal_before_erase(c_row, c_col, scr.cols, selective=selective)
scr._rows[c_row].clear_range(
c_col,
Expand All @@ -3682,9 +3681,14 @@ def _erase_display(
policy=sixel_pol,
)
self._notify_erase(Rect(c_row, c_col, 1, scr.cols - c_col), cause)
for r in range(c_row + 1, scr.rows):
scr._sever_incoming_wrap(r, selective=selective)
scr._rows[r].clear_range(0, scr.cols, bce_w, bce_e, selective=selective)
scr._clear_rows(
c_row + 1,
scr.rows,
bce_w,
bce_e,
selective=selective,
sever_boundary=phantom or selective,
)
if c_row + 1 < scr.rows:
if not selective and scr._gfx is not None and scr._gfx.has_sixels:
scr._gfx.erase_sixel_rect(
Expand All @@ -3701,10 +3705,8 @@ def _erase_display(
)
elif mode == 1:
end_c = scr.cols if phantom else c_col + 1
for r in range(c_row):
scr._sever_incoming_wrap(r, selective=selective)
scr._rows[r].clear_range(0, scr.cols, bce_w, bce_e, selective=selective)
if c_row == 0 or end_c >= scr.cols:
scr._clear_rows(0, c_row, bce_w, bce_e, selective=selective)
if c_row == 0 or (selective and end_c >= scr.cols):
scr._sever_incoming_wrap(c_row, selective=selective)
scr._heal_before_erase(c_row, 0, end_c, selective=selective)
scr._rows[c_row].clear_range(
Expand Down Expand Up @@ -3738,19 +3740,15 @@ def _erase_display(
self._notify_erase(Rect(0, 0, c_row, scr.cols), cause)
self._notify_erase(Rect(c_row, 0, 1, end_c), cause)
elif mode == 2:
for r in range(scr.rows):
scr._sever_incoming_wrap(r, selective=selective)
scr._rows[r].clear_range(0, scr.cols, bce_w, bce_e, selective=selective)
scr._clear_rows(0, scr.rows, bce_w, bce_e, selective=selective)
if not selective and scr._gfx is not None:
scr._gfx.clear_active_screen(scr._scrolled_total, scr.rows)
self._notify_erase(Rect(0, 0, scr.rows, scr.cols), cause)
elif mode == 22 and not selective:
if not self._screens.active_is_alt:
scr.push_scrollback_and_clear(bce_w)
else:
for r in range(scr.rows):
scr._sever_incoming_wrap(r)
scr._rows[r].clear_range(0, scr.cols, bce_w, bce_e)
scr._clear_rows(0, scr.rows, bce_w, bce_e)
if scr._gfx is not None:
scr._gfx.clear_active_screen(scr._scrolled_total, scr.rows)
self._notify_erase(Rect(0, 0, scr.rows, scr.cols), cause)
Expand All @@ -3775,7 +3773,8 @@ def _erase_line(
c_col = scr._cur_col
sixel_pol = self._profile.screen.sixel_erase_policy
if mode == 0:
scr._sever_incoming_wrap(c_row, start=c_col, selective=selective)
if c_col <= 1:
scr._sever_incoming_wrap(c_row, start=c_col, selective=selective)
scr._heal_before_erase(c_row, c_col, scr.cols, selective=selective)
scr._rows[c_row].clear_range(
c_col,
Expand Down
Loading
Loading