Skip to content

Commit 86d3bc3

Browse files
committed
Restore image resizing in fedify lookup command
- Replace temporary Sharp removal with proper Jimp-based image processing - Add support for Ghostty terminal emulator in graphics protocol detection - Fix image output to stderr to avoid interfering with command output - Convert images to PNG format for better terminal compatibility This restores the image resizing functionality that was temporarily removed in v1.8.2 due to Sharp compatibility issues with deno compile, using the existing Jimp library that's already available in the codebase.
1 parent 639d895 commit 86d3bc3

File tree

2 files changed

+26
-6
lines changed

2 files changed

+26
-6
lines changed

CHANGES.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,17 @@ Version 1.8.3
88

99
To be released.
1010

11+
### @fedify/cli
12+
13+
- Restored image resizing functionality in `fedify lookup` command by using
14+
the existing [Jimp] library for image manipulation. This properly displays
15+
`icon` and `image` fields with appropriate sizing in terminals.
16+
17+
- Added support for Ghostty terminal emulator for image rendering in
18+
`fedify lookup` command.
19+
20+
[Jimp]: https://jimp-dev.github.io/jimp/
21+
1122

1223
Version 1.8.2
1324
-------------

packages/cli/src/imagerenderer.ts

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { encodeBase64 } from "@std/encoding/base64";
2+
import { Jimp } from "./nodeinfo.ts";
23

34
export type TerminalType = "kitty" | "iterm2" | "none";
45

@@ -9,6 +10,7 @@ const KITTY_IDENTIFIERS: string[] = [
910
"warp",
1011
"wayst",
1112
"st",
13+
"ghostty",
1214
];
1315

1416
type KittyCommand = Record<string, string | number>;
@@ -76,7 +78,7 @@ export async function renderImageKitty(
7678

7779
const command = serializeGrCommand(chunkCmd, chunk);
7880

79-
Deno.stdout.writeSync(command);
81+
await Deno.stderr.write(command);
8082

8183
isFirst = false;
8284
}
@@ -92,7 +94,7 @@ export async function renderImageITerm2(
9294
const command = encoder.encode(
9395
`\x1b]1337;File=inline=1preserveAspectRatio=1:${base64Data}\x07\n`,
9496
);
95-
Deno.stdout.writeSync(command);
97+
await Deno.stderr.write(command);
9698
}
9799

98100
export async function downloadImage(url: string): Promise<string | null> {
@@ -118,18 +120,25 @@ export async function renderImages(
118120
const tempPath = await downloadImage(url.href);
119121
if (!tempPath) continue;
120122

121-
console.log(""); // clear the line before rendering image
123+
const convertedImagePath: `${string}.png` = `${tempPath}.converted.png`;
124+
const image = await Jimp.read(tempPath);
125+
await image.write(convertedImagePath);
126+
await Deno.remove(tempPath);
127+
128+
console.error(); // clear the line before rendering image
122129

123130
if (graphicsProtocol === "kitty") {
124-
await renderImageKitty(tempPath, {
131+
await renderImageKitty(convertedImagePath, {
125132
a: "T",
126133
f: 100, // specify the image format is png
127134
});
128135
} else if (graphicsProtocol === "iterm2") {
129-
await renderImageITerm2(tempPath);
136+
await renderImageITerm2(convertedImagePath);
130137
} else {
131138
continue;
132139
}
133-
console.log(""); // clear the line after rendering image
140+
console.error(); // clear the line after rendering image
134141
}
135142
}
143+
144+
// cSpell: ignore ghostty iterm konsole magick wezterm wayst

0 commit comments

Comments
 (0)