pi-image-preview 0.1.2 → 0.1.4
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/package.json +2 -2
- package/src/image-gallery.ts +33 -3
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-image-preview",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"description": "Image preview extension for pi coding agent
|
|
3
|
+
"version": "0.1.4",
|
|
4
|
+
"description": "Image preview extension for pi coding agent \u2014 renders inline image thumbnails above the editor using kitty graphics protocol with tmux support",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"pi-package",
|
|
7
7
|
"kitty",
|
package/src/image-gallery.ts
CHANGED
|
@@ -1,11 +1,37 @@
|
|
|
1
1
|
import {
|
|
2
2
|
type Component,
|
|
3
3
|
getCapabilities,
|
|
4
|
+
type ImageProtocol,
|
|
4
5
|
getImageDimensions,
|
|
5
6
|
calculateImageRows,
|
|
6
7
|
getCellDimensions,
|
|
7
8
|
} from "@mariozechner/pi-tui";
|
|
8
9
|
|
|
10
|
+
/**
|
|
11
|
+
* Detect image protocol support, working around pi-tui ≥0.67.6 which
|
|
12
|
+
* hardcodes `images: null` inside tmux/screen for safety. Our extension
|
|
13
|
+
* uses the Unicode placeholder protocol which is specifically designed
|
|
14
|
+
* to work inside tmux, so we can safely detect kitty-in-tmux ourselves.
|
|
15
|
+
*/
|
|
16
|
+
function detectImageProtocol(): ImageProtocol | null {
|
|
17
|
+
const caps = getCapabilities();
|
|
18
|
+
if (caps.images) return caps.images;
|
|
19
|
+
|
|
20
|
+
// pi-tui returns null inside tmux — check if the outer terminal is kitty
|
|
21
|
+
const inTmux = !!process.env.TMUX || (process.env.TERM?.toLowerCase() || "").startsWith("tmux");
|
|
22
|
+
if (inTmux) {
|
|
23
|
+
if (process.env.KITTY_WINDOW_ID || (process.env.TERM_PROGRAM?.toLowerCase() || "") === "kitty") {
|
|
24
|
+
return "kitty";
|
|
25
|
+
}
|
|
26
|
+
// ghostty and wezterm also support kitty graphics in tmux
|
|
27
|
+
const termProgram = process.env.TERM_PROGRAM?.toLowerCase() || "";
|
|
28
|
+
if (termProgram === "ghostty" || process.env.GHOSTTY_RESOURCES_DIR) return "kitty";
|
|
29
|
+
if (termProgram === "wezterm" || process.env.WEZTERM_PANE) return "kitty";
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
|
|
9
35
|
export interface GalleryTheme {
|
|
10
36
|
accent: (s: string) => string;
|
|
11
37
|
muted: (s: string) => string;
|
|
@@ -20,6 +46,7 @@ export interface GalleryImage {
|
|
|
20
46
|
}
|
|
21
47
|
|
|
22
48
|
const THUMB_MAX_WIDTH = 25;
|
|
49
|
+
const THUMB_MAX_ROWS = 15; // cap height so tall images don't overflow the terminal
|
|
23
50
|
const GAP = 2; // columns between images
|
|
24
51
|
|
|
25
52
|
// Monotonic counter for kitty image IDs — avoids birthday-paradox collisions
|
|
@@ -229,7 +256,7 @@ export class ImageGallery implements Component {
|
|
|
229
256
|
}
|
|
230
257
|
|
|
231
258
|
const lines: string[] = [];
|
|
232
|
-
const
|
|
259
|
+
const imageProtocol = detectImageProtocol();
|
|
233
260
|
|
|
234
261
|
// Header
|
|
235
262
|
const count = this.images.length;
|
|
@@ -239,7 +266,7 @@ export class ImageGallery implements Component {
|
|
|
239
266
|
: ` 📎 ${count} images attached`;
|
|
240
267
|
lines.push(this.theme.accent(headerText));
|
|
241
268
|
|
|
242
|
-
if (
|
|
269
|
+
if (imageProtocol === "kitty") {
|
|
243
270
|
this.renderKittyHorizontal(lines, width);
|
|
244
271
|
} else {
|
|
245
272
|
this.renderTextFallback(lines);
|
|
@@ -276,7 +303,10 @@ export class ImageGallery implements Component {
|
|
|
276
303
|
heightPx: 600,
|
|
277
304
|
};
|
|
278
305
|
|
|
279
|
-
const rows =
|
|
306
|
+
const rows = Math.min(
|
|
307
|
+
calculateImageRows(dims, thumbWidth, getCellDimensions()),
|
|
308
|
+
THUMB_MAX_ROWS,
|
|
309
|
+
);
|
|
280
310
|
const imageId = allocateImageId();
|
|
281
311
|
this.activeImageIds.push(imageId);
|
|
282
312
|
|