mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-21 02:04:32 +00:00
Fix image aspect ratio by querying terminal cell size
- Add getCellDimensions/setCellDimensions to terminal-image.ts - TUI queries cell size on startup via CSI 16 t - Parse response and filter it from user input - Invalidate and re-render when cell dimensions received - Pass rows parameter to Kitty protocol for correct aspect ratio
This commit is contained in:
parent
fcad447f32
commit
215c10664a
3 changed files with 93 additions and 9 deletions
|
|
@ -24,6 +24,17 @@ export interface ImageRenderOptions {
|
|||
|
||||
let cachedCapabilities: TerminalCapabilities | null = null;
|
||||
|
||||
// Default cell dimensions - updated by TUI when terminal responds to query
|
||||
let cellDimensions: CellDimensions = { widthPx: 9, heightPx: 18 };
|
||||
|
||||
export function getCellDimensions(): CellDimensions {
|
||||
return cellDimensions;
|
||||
}
|
||||
|
||||
export function setCellDimensions(dims: CellDimensions): void {
|
||||
cellDimensions = dims;
|
||||
}
|
||||
|
||||
export function detectCapabilities(): TerminalCapabilities {
|
||||
const termProgram = process.env.TERM_PROGRAM?.toLowerCase() || "";
|
||||
const term = process.env.TERM?.toLowerCase() || "";
|
||||
|
|
@ -307,11 +318,10 @@ export function renderImage(
|
|||
}
|
||||
|
||||
const maxWidth = options.maxWidthCells ?? 80;
|
||||
const cellDims: CellDimensions = { widthPx: 9, heightPx: 18 };
|
||||
const rows = calculateImageRows(imageDimensions, maxWidth, cellDims);
|
||||
const rows = calculateImageRows(imageDimensions, maxWidth, getCellDimensions());
|
||||
|
||||
if (caps.images === "kitty") {
|
||||
const sequence = encodeKitty(base64Data, { columns: maxWidth });
|
||||
const sequence = encodeKitty(base64Data, { columns: maxWidth, rows });
|
||||
return { sequence, rows };
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue