feat: Improve Sixel rendering stability by adjusting output height and anchoring behavior

Signed-off-by: Hans Kokx <hans.d.kokx@gmail.com>
This commit is contained in:
2026-03-20 18:03:19 +01:00
parent 1e5222368a
commit 2598218a4d
2 changed files with 25 additions and 12 deletions

View File

@@ -200,14 +200,22 @@ class SixelRenderer extends CliRendererBackend<String> {
// Horizontal: cell-width estimates vary by terminal/font and can cause
// right-shift clipping, so keep the image anchored at column 0.
// Vertical: keep one spare row to avoid scroll, but anchor to the bottom
// of the viewport so we avoid obvious empty space under the image.
final int imageRows = math.max(
1,
(_outputHeight / _defaultLineHeightPx).ceil() + _terminalRowSafetyMargin,
);
// Vertical: force top anchoring to keep repaint location stable across
// terminals that still scroll when rendering near the bottom edge.
_offsetColumns = 0;
_offsetRows = math.max(0, terminalRows - imageRows);
_offsetRows = 0;
// Clamp output height to a conservative terminal-row budget so Sixel data
// cannot extend beyond the viewport and trigger implicit scroll.
final int maxImageRows = math.max(
1,
terminalRows - _terminalRowSafetyMargin,
);
final int maxOutputHeight = maxImageRows * _defaultLineHeightPx;
if (_outputHeight > maxOutputHeight) {
_outputHeight = maxOutputHeight;
_outputWidth = math.max(1, (_outputHeight * _targetAspectRatio).floor());
}
if (_offsetColumns != previousOffsetColumns ||
_offsetRows != previousOffsetRows ||