fix(tui): cap portrait image render height

This commit is contained in:
Mario Zechner
2026-05-13 16:11:40 +02:00
parent c00f1cf130
commit e3faf41801
4 changed files with 82 additions and 12 deletions

View File

@@ -1,6 +1,7 @@
import {
allocateImageId,
getCapabilities,
getCellDimensions,
getImageDimensions,
type ImageDimensions,
imageFallback,
@@ -61,7 +62,10 @@ export class Image implements Component {
return this.cachedLines;
}
const maxWidth = Math.min(width - 2, this.options.maxWidthCells ?? 60);
const maxWidth = Math.max(1, Math.min(width - 2, this.options.maxWidthCells ?? 60));
const cellDimensions = getCellDimensions();
const defaultMaxHeight = Math.max(1, Math.ceil((maxWidth * cellDimensions.widthPx) / cellDimensions.heightPx));
const maxHeight = this.options.maxHeightCells ?? defaultMaxHeight;
const caps = getCapabilities();
let lines: string[];
@@ -72,6 +76,7 @@ export class Image implements Component {
}
const result = renderImage(this.base64Data, this.dimensions, {
maxWidthCells: maxWidth,
maxHeightCells: maxHeight,
imageId: this.imageId,
moveCursor: false,
});