Skip to content

feat: add row-level diff rendering #179

Open
domenkozar wants to merge 4 commits intoccbrown:mainfrom
cachix:row-level-diff
Open

feat: add row-level diff rendering #179
domenkozar wants to merge 4 commits intoccbrown:mainfrom
cachix:row-level-diff

Conversation

@domenkozar
Copy link
Copy Markdown
Contributor

@domenkozar domenkozar commented Mar 19, 2026

What It Does

Extract per-row rendering from Canvas so individual rows can be written and compared independently. The terminal now diffs against the previous canvas and only re-renders rows that changed, reducing flicker and redundant output in both fullscreen and inline modes.

In fullscreen mode, absolute cursor positioning targets only changed rows. In inline mode, relative cursor movement achieves the same. The clear_canvas path in fullscreen mode now preserves output above the canvas area.

I'd be happy to add more tests for regressions since it's a substantial change in the core logic of rendering.

Related Issues

#117

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 19, 2026

Codecov Report

❌ Patch coverage is 93.49931% with 47 lines in your changes missing coverage. Please review.
✅ Project coverage is 88.79%. Comparing base (6581aa2) to head (5e6ca04).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
packages/iocraft/src/terminal.rs 94.95% 8 Missing and 20 partials ⚠️
packages/iocraft/src/canvas.rs 88.95% 4 Missing and 14 partials ⚠️
packages/iocraft/src/render.rs 75.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #179      +/-   ##
==========================================
- Coverage   88.81%   88.79%   -0.02%     
==========================================
  Files          34       34              
  Lines        5945     5946       +1     
  Branches     5945     5946       +1     
==========================================
  Hits         5280     5280              
+ Misses        550      540      -10     
- Partials      115      126      +11     
Files with missing lines Coverage Δ
packages/iocraft/src/components/text.rs 98.87% <100.00%> (-0.09%) ⬇️
packages/iocraft/src/render.rs 93.08% <75.00%> (-0.42%) ⬇️
packages/iocraft/src/canvas.rs 94.50% <88.95%> (-0.67%) ⬇️
packages/iocraft/src/terminal.rs 87.10% <94.95%> (+11.43%) ⬆️

... and 25 files with indirect coverage changes

Impacted file tree graph

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Extract per-row rendering from Canvas so individual rows can be
written and compared independently. The terminal now diffs against
the previous canvas and only re-renders rows that changed, reducing
flicker and redundant output in both fullscreen and inline modes.

In fullscreen mode, absolute cursor positioning targets only changed
rows. In inline mode, relative cursor movement achieves the same.
The clear_canvas path in fullscreen mode now preserves output above
the canvas area.

Co-Authored-By: Samuel Corsi-House <sam@chouse.dev>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
domenkozar added a commit to cachix/devenv that referenced this pull request Mar 19, 2026
This reduces TUI flicker by only re-rendering rows that changed.
Also bumps crossterm to 0.29.0 to match iocraft's dependency.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@domenkozar
Copy link
Copy Markdown
Contributor Author

We're releasing this part of devenv 2.0.6 and will let you know what folks say.

domenkozar added a commit to cachix/devenv that referenced this pull request Mar 20, 2026
…#179)"

This reverts commit 037d76f.

I'm seeing some weird output with duplicated Configuring shell, revert
for now.
@ccbrown
Copy link
Copy Markdown
Owner

ccbrown commented Mar 20, 2026

Thanks for the PR! It looks great at a glance, but I'll do my best to review this fully in the next few days.

@owtaylor
Copy link
Copy Markdown

Neat stuff! - it was pretty much exactly what I needed for a project that I'm working on. I gave it some testing and found some issues with inline mode:

  • Adding lines at the bottom edge of the screen wasn't right - it tried to move the cursor down to add another line, but couldn't. Newlines needed to be added instead to force scrolling.
  • In the case of an inline buffer larger than the screen (the render_loop duplicate rendering issue #118 case), we don't want to use the scrollback-buffer-clearing fallback if we can avoid it - clearing the scrollback buffer, and rewriting everything is very likely to cause flashing, so there's a huge win in being precise.

I've put fixes for these at https://github.com/owtaylor/iocraft/tree/row-level-diff-fixes - feel free to add them to your PR if they look useful.

owtaylor and others added 3 commits March 25, 2026 05:47
When the canvas grows beyond its previous height, MoveToNextLine (CSI E)
was used to reach the new rows. CSI E only repositions within existing
terminal content — it won't create new lines when the cursor is at the
bottom of the screen. Use \r\n instead for rows beyond the previous
canvas height to actually extend the scrollback.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Instead of unconditionally clearing when the canvas height >= terminal
height, check each changed row during the diff. Only fall back to a
full rewrite if a changed row is above the visible area (off-screen).
When only visible rows changed, the normal row-level diff handles it
without any flicker.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@domenkozar
Copy link
Copy Markdown
Contributor Author

Thanks @owtaylor I've pulled your fixes in!

@ccbrown ccbrown self-requested a review March 25, 2026 20:42
@ccbrown ccbrown added the enhancement New feature or request label Mar 25, 2026
@domenkozar
Copy link
Copy Markdown
Contributor Author

Note that I've reverted this change in devenv for now as it doesn't fully work yet. I'll test the bug fixes in following days.

@pamelia
Copy link
Copy Markdown

pamelia commented Mar 31, 2026

looking forward to this!

AodhanHayter pushed a commit to AodhanHayter/devenv that referenced this pull request Apr 3, 2026
…#179)"

This reverts commit 037d76f.

I'm seeing some weird output with duplicated Configuring shell, revert
for now.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants