Add differential redraw for animated plots (new - prev)#5
Draft
matomatical wants to merge 1 commit into
Draft
Conversation
Animating a plot currently clears the whole region (`-plot`) and redraws every cell. This adds a differential path: `new - prev` (sugar for `new.updatestr(prev)`, backed by `CharArray.to_ansi_diff_str`) emits a minimal ANSI sequence that repaints only the cells differing from the previous frame -- jumping the cursor with relative moves and carrying SGR colour state across the skipped gaps. Falls back to a full clear-and-redraw on a size change. The cursor contract mirrors the existing idiom: assumes the cursor is just below `prev` (as after printing it) and leaves it just below `new`. Correctness is verified against a small ANSI terminal emulator in the tests: applying a diff to a screen showing `prev` reproduces a full redraw of `new`, across 40 randomised partial-change cases, plus focused tests (no-change, single-cell, colour-only, size-mismatch fallback, final cursor position). Byte savings are large for mostly-static animations (~13x on a dashboard with one moving bar) and modest for fully turbulent frames where most cells change. Ticks the roadmap item; CHANGELOG updated. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Animating a plot currently clears the whole region (
-plot) and redraws every cell. This adds a differential path:new - prev(sugar fornew.updatestr(prev), backed byCharArray.to_ansi_diff_str) emits a minimal ANSI sequence that repaints only the cells differing from the previous frame -- jumping the cursor with relative moves and carrying SGR colour state across the skipped gaps. Falls back to a full clear-and-redraw on a size change.The cursor contract mirrors the existing idiom: assumes the cursor is just below
prev(as after printing it) and leaves it just belownew.Correctness is verified against a small ANSI terminal emulator in the tests: applying a diff to a screen showing
prevreproduces a full redraw ofnew, across 40 randomised partial-change cases, plus focused tests (no-change, single-cell, colour-only, size-mismatch fallback, final cursor position).Byte savings are large for mostly-static animations (~13x on a dashboard with one moving bar) and modest for fully turbulent frames where most cells change.
Ticks the roadmap item; CHANGELOG updated.
What
Animating a plot currently clears the whole region (
-plot) and repaints everycell. This adds a differential path:
new - prev(sugar fornew.updatestr(prev), backed byCharArray.to_ansi_diff_str) emits a minimalANSI sequence that repaints only the cells that changed since the previous
frame — stepping the cursor with relative moves and carrying SGR colour state
across the skipped gaps. Falls back to a full clear-and-redraw on a size change.
Implements the roadmap item "Faster animated plot redraws (differential
rendering with shortcut
-)."API
Cursor contract: assumes the cursor is just below
prev(as after printing it)and leaves it just below
new; single-width glyphs at column 0.Verified
prevreproduces a full redraw of
new— 40 randomised partial-change cases, plusno-change / single-cell / colour-only / size-mismatch-fallback / cursor cases.
mypyclean on the new code (the 2histogramoverload errors pre-exist on
main).Byte savings (encoded, vs full redraw)
Big win for mostly-static animations; modest for fully turbulent frames.
Notes
DOCS.mdnot regenerated (nogenerate_docs.pyin repo); API docs come frompdoc reading the new docstrings.
🤖 Generated with Claude Code