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:
@@ -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 ||
|
||||
|
||||
Reference in New Issue
Block a user