@lenylvt/pi-tui 0.62.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +767 -0
- package/dist/autocomplete.d.ts +50 -0
- package/dist/autocomplete.d.ts.map +1 -0
- package/dist/autocomplete.js +623 -0
- package/dist/autocomplete.js.map +1 -0
- package/dist/components/box.d.ts +22 -0
- package/dist/components/box.d.ts.map +1 -0
- package/dist/components/box.js +104 -0
- package/dist/components/box.js.map +1 -0
- package/dist/components/cancellable-loader.d.ts +22 -0
- package/dist/components/cancellable-loader.d.ts.map +1 -0
- package/dist/components/cancellable-loader.js +35 -0
- package/dist/components/cancellable-loader.js.map +1 -0
- package/dist/components/editor.d.ts +244 -0
- package/dist/components/editor.d.ts.map +1 -0
- package/dist/components/editor.js +1861 -0
- package/dist/components/editor.js.map +1 -0
- package/dist/components/image.d.ts +28 -0
- package/dist/components/image.d.ts.map +1 -0
- package/dist/components/image.js +69 -0
- package/dist/components/image.js.map +1 -0
- package/dist/components/input.d.ts +37 -0
- package/dist/components/input.d.ts.map +1 -0
- package/dist/components/input.js +426 -0
- package/dist/components/input.js.map +1 -0
- package/dist/components/loader.d.ts +21 -0
- package/dist/components/loader.d.ts.map +1 -0
- package/dist/components/loader.js +49 -0
- package/dist/components/loader.js.map +1 -0
- package/dist/components/markdown.d.ts +95 -0
- package/dist/components/markdown.d.ts.map +1 -0
- package/dist/components/markdown.js +660 -0
- package/dist/components/markdown.js.map +1 -0
- package/dist/components/select-list.d.ts +50 -0
- package/dist/components/select-list.d.ts.map +1 -0
- package/dist/components/select-list.js +159 -0
- package/dist/components/select-list.js.map +1 -0
- package/dist/components/settings-list.d.ts +50 -0
- package/dist/components/settings-list.d.ts.map +1 -0
- package/dist/components/settings-list.js +185 -0
- package/dist/components/settings-list.js.map +1 -0
- package/dist/components/spacer.d.ts +12 -0
- package/dist/components/spacer.d.ts.map +1 -0
- package/dist/components/spacer.js +23 -0
- package/dist/components/spacer.js.map +1 -0
- package/dist/components/text.d.ts +19 -0
- package/dist/components/text.d.ts.map +1 -0
- package/dist/components/text.js +89 -0
- package/dist/components/text.js.map +1 -0
- package/dist/components/truncated-text.d.ts +13 -0
- package/dist/components/truncated-text.d.ts.map +1 -0
- package/dist/components/truncated-text.js +51 -0
- package/dist/components/truncated-text.js.map +1 -0
- package/dist/editor-component.d.ts +39 -0
- package/dist/editor-component.d.ts.map +1 -0
- package/dist/editor-component.js +2 -0
- package/dist/editor-component.js.map +1 -0
- package/dist/fuzzy.d.ts +16 -0
- package/dist/fuzzy.d.ts.map +1 -0
- package/dist/fuzzy.js +107 -0
- package/dist/fuzzy.js.map +1 -0
- package/dist/index.d.ts +23 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +32 -0
- package/dist/index.js.map +1 -0
- package/dist/keybindings.d.ts +193 -0
- package/dist/keybindings.d.ts.map +1 -0
- package/dist/keybindings.js +174 -0
- package/dist/keybindings.js.map +1 -0
- package/dist/keys.d.ts +170 -0
- package/dist/keys.d.ts.map +1 -0
- package/dist/keys.js +1124 -0
- package/dist/keys.js.map +1 -0
- package/dist/kill-ring.d.ts +28 -0
- package/dist/kill-ring.d.ts.map +1 -0
- package/dist/kill-ring.js +44 -0
- package/dist/kill-ring.js.map +1 -0
- package/dist/stdin-buffer.d.ts +48 -0
- package/dist/stdin-buffer.d.ts.map +1 -0
- package/dist/stdin-buffer.js +317 -0
- package/dist/stdin-buffer.js.map +1 -0
- package/dist/terminal-image.d.ts +68 -0
- package/dist/terminal-image.d.ts.map +1 -0
- package/dist/terminal-image.js +288 -0
- package/dist/terminal-image.js.map +1 -0
- package/dist/terminal.d.ts +84 -0
- package/dist/terminal.d.ts.map +1 -0
- package/dist/terminal.js +285 -0
- package/dist/terminal.js.map +1 -0
- package/dist/tui.d.ts +218 -0
- package/dist/tui.d.ts.map +1 -0
- package/dist/tui.js +966 -0
- package/dist/tui.js.map +1 -0
- package/dist/undo-stack.d.ts +17 -0
- package/dist/undo-stack.d.ts.map +1 -0
- package/dist/undo-stack.js +25 -0
- package/dist/undo-stack.js.map +1 -0
- package/dist/utils.d.ts +78 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +960 -0
- package/dist/utils.js.map +1 -0
- package/package.json +55 -0
- package/src/autocomplete.ts +771 -0
- package/src/components/box.ts +137 -0
- package/src/components/cancellable-loader.ts +40 -0
- package/src/components/editor.ts +2230 -0
- package/src/components/image.ts +104 -0
- package/src/components/input.ts +503 -0
- package/src/components/loader.ts +55 -0
- package/src/components/markdown.ts +820 -0
- package/src/components/select-list.ts +229 -0
- package/src/components/settings-list.ts +250 -0
- package/src/components/spacer.ts +28 -0
- package/src/components/text.ts +106 -0
- package/src/components/truncated-text.ts +65 -0
- package/src/editor-component.ts +74 -0
- package/src/fuzzy.ts +133 -0
- package/src/index.ts +104 -0
- package/src/keybindings.ts +244 -0
- package/src/keys.ts +1356 -0
- package/src/kill-ring.ts +46 -0
- package/src/stdin-buffer.ts +386 -0
- package/src/terminal-image.ts +381 -0
- package/src/terminal.ts +360 -0
- package/src/tui.ts +1200 -0
- package/src/undo-stack.ts +28 -0
- package/src/utils.ts +1068 -0
|
@@ -0,0 +1,381 @@
|
|
|
1
|
+
export type ImageProtocol = "kitty" | "iterm2" | null;
|
|
2
|
+
|
|
3
|
+
export interface TerminalCapabilities {
|
|
4
|
+
images: ImageProtocol;
|
|
5
|
+
trueColor: boolean;
|
|
6
|
+
hyperlinks: boolean;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export interface CellDimensions {
|
|
10
|
+
widthPx: number;
|
|
11
|
+
heightPx: number;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface ImageDimensions {
|
|
15
|
+
widthPx: number;
|
|
16
|
+
heightPx: number;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface ImageRenderOptions {
|
|
20
|
+
maxWidthCells?: number;
|
|
21
|
+
maxHeightCells?: number;
|
|
22
|
+
preserveAspectRatio?: boolean;
|
|
23
|
+
/** Kitty image ID. If provided, reuses/replaces existing image with this ID. */
|
|
24
|
+
imageId?: number;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
let cachedCapabilities: TerminalCapabilities | null = null;
|
|
28
|
+
|
|
29
|
+
// Default cell dimensions - updated by TUI when terminal responds to query
|
|
30
|
+
let cellDimensions: CellDimensions = { widthPx: 9, heightPx: 18 };
|
|
31
|
+
|
|
32
|
+
export function getCellDimensions(): CellDimensions {
|
|
33
|
+
return cellDimensions;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function setCellDimensions(dims: CellDimensions): void {
|
|
37
|
+
cellDimensions = dims;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function detectCapabilities(): TerminalCapabilities {
|
|
41
|
+
const termProgram = process.env.TERM_PROGRAM?.toLowerCase() || "";
|
|
42
|
+
const term = process.env.TERM?.toLowerCase() || "";
|
|
43
|
+
const colorTerm = process.env.COLORTERM?.toLowerCase() || "";
|
|
44
|
+
|
|
45
|
+
if (process.env.KITTY_WINDOW_ID || termProgram === "kitty") {
|
|
46
|
+
return { images: "kitty", trueColor: true, hyperlinks: true };
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if (termProgram === "ghostty" || term.includes("ghostty") || process.env.GHOSTTY_RESOURCES_DIR) {
|
|
50
|
+
return { images: "kitty", trueColor: true, hyperlinks: true };
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (process.env.WEZTERM_PANE || termProgram === "wezterm") {
|
|
54
|
+
return { images: "kitty", trueColor: true, hyperlinks: true };
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (process.env.ITERM_SESSION_ID || termProgram === "iterm.app") {
|
|
58
|
+
return { images: "iterm2", trueColor: true, hyperlinks: true };
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (termProgram === "vscode") {
|
|
62
|
+
return { images: null, trueColor: true, hyperlinks: true };
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if (termProgram === "alacritty") {
|
|
66
|
+
return { images: null, trueColor: true, hyperlinks: true };
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const trueColor = colorTerm === "truecolor" || colorTerm === "24bit";
|
|
70
|
+
return { images: null, trueColor, hyperlinks: true };
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export function getCapabilities(): TerminalCapabilities {
|
|
74
|
+
if (!cachedCapabilities) {
|
|
75
|
+
cachedCapabilities = detectCapabilities();
|
|
76
|
+
}
|
|
77
|
+
return cachedCapabilities;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export function resetCapabilitiesCache(): void {
|
|
81
|
+
cachedCapabilities = null;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const KITTY_PREFIX = "\x1b_G";
|
|
85
|
+
const ITERM2_PREFIX = "\x1b]1337;File=";
|
|
86
|
+
|
|
87
|
+
export function isImageLine(line: string): boolean {
|
|
88
|
+
// Fast path: sequence at line start (single-row images)
|
|
89
|
+
if (line.startsWith(KITTY_PREFIX) || line.startsWith(ITERM2_PREFIX)) {
|
|
90
|
+
return true;
|
|
91
|
+
}
|
|
92
|
+
// Slow path: sequence elsewhere (multi-row images have cursor-up prefix)
|
|
93
|
+
return line.includes(KITTY_PREFIX) || line.includes(ITERM2_PREFIX);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Generate a random image ID for Kitty graphics protocol.
|
|
98
|
+
* Uses random IDs to avoid collisions between different module instances
|
|
99
|
+
* (e.g., main app vs extensions).
|
|
100
|
+
*/
|
|
101
|
+
export function allocateImageId(): number {
|
|
102
|
+
// Use random ID in range [1, 0xffffffff] to avoid collisions
|
|
103
|
+
return Math.floor(Math.random() * 0xfffffffe) + 1;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export function encodeKitty(
|
|
107
|
+
base64Data: string,
|
|
108
|
+
options: {
|
|
109
|
+
columns?: number;
|
|
110
|
+
rows?: number;
|
|
111
|
+
imageId?: number;
|
|
112
|
+
} = {},
|
|
113
|
+
): string {
|
|
114
|
+
const CHUNK_SIZE = 4096;
|
|
115
|
+
|
|
116
|
+
const params: string[] = ["a=T", "f=100", "q=2"];
|
|
117
|
+
|
|
118
|
+
if (options.columns) params.push(`c=${options.columns}`);
|
|
119
|
+
if (options.rows) params.push(`r=${options.rows}`);
|
|
120
|
+
if (options.imageId) params.push(`i=${options.imageId}`);
|
|
121
|
+
|
|
122
|
+
if (base64Data.length <= CHUNK_SIZE) {
|
|
123
|
+
return `\x1b_G${params.join(",")};${base64Data}\x1b\\`;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
const chunks: string[] = [];
|
|
127
|
+
let offset = 0;
|
|
128
|
+
let isFirst = true;
|
|
129
|
+
|
|
130
|
+
while (offset < base64Data.length) {
|
|
131
|
+
const chunk = base64Data.slice(offset, offset + CHUNK_SIZE);
|
|
132
|
+
const isLast = offset + CHUNK_SIZE >= base64Data.length;
|
|
133
|
+
|
|
134
|
+
if (isFirst) {
|
|
135
|
+
chunks.push(`\x1b_G${params.join(",")},m=1;${chunk}\x1b\\`);
|
|
136
|
+
isFirst = false;
|
|
137
|
+
} else if (isLast) {
|
|
138
|
+
chunks.push(`\x1b_Gm=0;${chunk}\x1b\\`);
|
|
139
|
+
} else {
|
|
140
|
+
chunks.push(`\x1b_Gm=1;${chunk}\x1b\\`);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
offset += CHUNK_SIZE;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
return chunks.join("");
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Delete a Kitty graphics image by ID.
|
|
151
|
+
* Uses uppercase 'I' to also free the image data.
|
|
152
|
+
*/
|
|
153
|
+
export function deleteKittyImage(imageId: number): string {
|
|
154
|
+
return `\x1b_Ga=d,d=I,i=${imageId}\x1b\\`;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Delete all visible Kitty graphics images.
|
|
159
|
+
* Uses uppercase 'A' to also free the image data.
|
|
160
|
+
*/
|
|
161
|
+
export function deleteAllKittyImages(): string {
|
|
162
|
+
return `\x1b_Ga=d,d=A\x1b\\`;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
export function encodeITerm2(
|
|
166
|
+
base64Data: string,
|
|
167
|
+
options: {
|
|
168
|
+
width?: number | string;
|
|
169
|
+
height?: number | string;
|
|
170
|
+
name?: string;
|
|
171
|
+
preserveAspectRatio?: boolean;
|
|
172
|
+
inline?: boolean;
|
|
173
|
+
} = {},
|
|
174
|
+
): string {
|
|
175
|
+
const params: string[] = [`inline=${options.inline !== false ? 1 : 0}`];
|
|
176
|
+
|
|
177
|
+
if (options.width !== undefined) params.push(`width=${options.width}`);
|
|
178
|
+
if (options.height !== undefined) params.push(`height=${options.height}`);
|
|
179
|
+
if (options.name) {
|
|
180
|
+
const nameBase64 = Buffer.from(options.name).toString("base64");
|
|
181
|
+
params.push(`name=${nameBase64}`);
|
|
182
|
+
}
|
|
183
|
+
if (options.preserveAspectRatio === false) {
|
|
184
|
+
params.push("preserveAspectRatio=0");
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
return `\x1b]1337;File=${params.join(";")}:${base64Data}\x07`;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
export function calculateImageRows(
|
|
191
|
+
imageDimensions: ImageDimensions,
|
|
192
|
+
targetWidthCells: number,
|
|
193
|
+
cellDimensions: CellDimensions = { widthPx: 9, heightPx: 18 },
|
|
194
|
+
): number {
|
|
195
|
+
const targetWidthPx = targetWidthCells * cellDimensions.widthPx;
|
|
196
|
+
const scale = targetWidthPx / imageDimensions.widthPx;
|
|
197
|
+
const scaledHeightPx = imageDimensions.heightPx * scale;
|
|
198
|
+
const rows = Math.ceil(scaledHeightPx / cellDimensions.heightPx);
|
|
199
|
+
return Math.max(1, rows);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
export function getPngDimensions(base64Data: string): ImageDimensions | null {
|
|
203
|
+
try {
|
|
204
|
+
const buffer = Buffer.from(base64Data, "base64");
|
|
205
|
+
|
|
206
|
+
if (buffer.length < 24) {
|
|
207
|
+
return null;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
if (buffer[0] !== 0x89 || buffer[1] !== 0x50 || buffer[2] !== 0x4e || buffer[3] !== 0x47) {
|
|
211
|
+
return null;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
const width = buffer.readUInt32BE(16);
|
|
215
|
+
const height = buffer.readUInt32BE(20);
|
|
216
|
+
|
|
217
|
+
return { widthPx: width, heightPx: height };
|
|
218
|
+
} catch {
|
|
219
|
+
return null;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
export function getJpegDimensions(base64Data: string): ImageDimensions | null {
|
|
224
|
+
try {
|
|
225
|
+
const buffer = Buffer.from(base64Data, "base64");
|
|
226
|
+
|
|
227
|
+
if (buffer.length < 2) {
|
|
228
|
+
return null;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
if (buffer[0] !== 0xff || buffer[1] !== 0xd8) {
|
|
232
|
+
return null;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
let offset = 2;
|
|
236
|
+
while (offset < buffer.length - 9) {
|
|
237
|
+
if (buffer[offset] !== 0xff) {
|
|
238
|
+
offset++;
|
|
239
|
+
continue;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
const marker = buffer[offset + 1];
|
|
243
|
+
|
|
244
|
+
if (marker >= 0xc0 && marker <= 0xc2) {
|
|
245
|
+
const height = buffer.readUInt16BE(offset + 5);
|
|
246
|
+
const width = buffer.readUInt16BE(offset + 7);
|
|
247
|
+
return { widthPx: width, heightPx: height };
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
if (offset + 3 >= buffer.length) {
|
|
251
|
+
return null;
|
|
252
|
+
}
|
|
253
|
+
const length = buffer.readUInt16BE(offset + 2);
|
|
254
|
+
if (length < 2) {
|
|
255
|
+
return null;
|
|
256
|
+
}
|
|
257
|
+
offset += 2 + length;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
return null;
|
|
261
|
+
} catch {
|
|
262
|
+
return null;
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
export function getGifDimensions(base64Data: string): ImageDimensions | null {
|
|
267
|
+
try {
|
|
268
|
+
const buffer = Buffer.from(base64Data, "base64");
|
|
269
|
+
|
|
270
|
+
if (buffer.length < 10) {
|
|
271
|
+
return null;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
const sig = buffer.slice(0, 6).toString("ascii");
|
|
275
|
+
if (sig !== "GIF87a" && sig !== "GIF89a") {
|
|
276
|
+
return null;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
const width = buffer.readUInt16LE(6);
|
|
280
|
+
const height = buffer.readUInt16LE(8);
|
|
281
|
+
|
|
282
|
+
return { widthPx: width, heightPx: height };
|
|
283
|
+
} catch {
|
|
284
|
+
return null;
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
export function getWebpDimensions(base64Data: string): ImageDimensions | null {
|
|
289
|
+
try {
|
|
290
|
+
const buffer = Buffer.from(base64Data, "base64");
|
|
291
|
+
|
|
292
|
+
if (buffer.length < 30) {
|
|
293
|
+
return null;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
const riff = buffer.slice(0, 4).toString("ascii");
|
|
297
|
+
const webp = buffer.slice(8, 12).toString("ascii");
|
|
298
|
+
if (riff !== "RIFF" || webp !== "WEBP") {
|
|
299
|
+
return null;
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
const chunk = buffer.slice(12, 16).toString("ascii");
|
|
303
|
+
if (chunk === "VP8 ") {
|
|
304
|
+
if (buffer.length < 30) return null;
|
|
305
|
+
const width = buffer.readUInt16LE(26) & 0x3fff;
|
|
306
|
+
const height = buffer.readUInt16LE(28) & 0x3fff;
|
|
307
|
+
return { widthPx: width, heightPx: height };
|
|
308
|
+
} else if (chunk === "VP8L") {
|
|
309
|
+
if (buffer.length < 25) return null;
|
|
310
|
+
const bits = buffer.readUInt32LE(21);
|
|
311
|
+
const width = (bits & 0x3fff) + 1;
|
|
312
|
+
const height = ((bits >> 14) & 0x3fff) + 1;
|
|
313
|
+
return { widthPx: width, heightPx: height };
|
|
314
|
+
} else if (chunk === "VP8X") {
|
|
315
|
+
if (buffer.length < 30) return null;
|
|
316
|
+
const width = (buffer[24] | (buffer[25] << 8) | (buffer[26] << 16)) + 1;
|
|
317
|
+
const height = (buffer[27] | (buffer[28] << 8) | (buffer[29] << 16)) + 1;
|
|
318
|
+
return { widthPx: width, heightPx: height };
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
return null;
|
|
322
|
+
} catch {
|
|
323
|
+
return null;
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
export function getImageDimensions(base64Data: string, mimeType: string): ImageDimensions | null {
|
|
328
|
+
if (mimeType === "image/png") {
|
|
329
|
+
return getPngDimensions(base64Data);
|
|
330
|
+
}
|
|
331
|
+
if (mimeType === "image/jpeg") {
|
|
332
|
+
return getJpegDimensions(base64Data);
|
|
333
|
+
}
|
|
334
|
+
if (mimeType === "image/gif") {
|
|
335
|
+
return getGifDimensions(base64Data);
|
|
336
|
+
}
|
|
337
|
+
if (mimeType === "image/webp") {
|
|
338
|
+
return getWebpDimensions(base64Data);
|
|
339
|
+
}
|
|
340
|
+
return null;
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
export function renderImage(
|
|
344
|
+
base64Data: string,
|
|
345
|
+
imageDimensions: ImageDimensions,
|
|
346
|
+
options: ImageRenderOptions = {},
|
|
347
|
+
): { sequence: string; rows: number; imageId?: number } | null {
|
|
348
|
+
const caps = getCapabilities();
|
|
349
|
+
|
|
350
|
+
if (!caps.images) {
|
|
351
|
+
return null;
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
const maxWidth = options.maxWidthCells ?? 80;
|
|
355
|
+
const rows = calculateImageRows(imageDimensions, maxWidth, getCellDimensions());
|
|
356
|
+
|
|
357
|
+
if (caps.images === "kitty") {
|
|
358
|
+
// Only use imageId if explicitly provided - static images don't need IDs
|
|
359
|
+
const sequence = encodeKitty(base64Data, { columns: maxWidth, rows, imageId: options.imageId });
|
|
360
|
+
return { sequence, rows, imageId: options.imageId };
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
if (caps.images === "iterm2") {
|
|
364
|
+
const sequence = encodeITerm2(base64Data, {
|
|
365
|
+
width: maxWidth,
|
|
366
|
+
height: "auto",
|
|
367
|
+
preserveAspectRatio: options.preserveAspectRatio ?? true,
|
|
368
|
+
});
|
|
369
|
+
return { sequence, rows };
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
return null;
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
export function imageFallback(mimeType: string, dimensions?: ImageDimensions, filename?: string): string {
|
|
376
|
+
const parts: string[] = [];
|
|
377
|
+
if (filename) parts.push(filename);
|
|
378
|
+
parts.push(`[${mimeType}]`);
|
|
379
|
+
if (dimensions) parts.push(`${dimensions.widthPx}x${dimensions.heightPx}`);
|
|
380
|
+
return `[Image: ${parts.join(" ")}]`;
|
|
381
|
+
}
|