Skip to content

Commit c38b809

Browse files
Add preferNativeRender option (#47)
Co-authored-by: Sindre Sorhus <[email protected]>
1 parent c3965e1 commit c38b809

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

index.d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ declare const terminalImage: {
3333
@param options.width - Optional: Custom image width. Can be set as percentage or number of columns of the terminal. It is recommended to use the percentage options.
3434
@param options.height - Optional: Custom image height. Can be set as percentage or number of rows of the terminal. It is recommended to use the percentage options.
3535
@param options.preserveAspectRatio - Optional: Whether to maintain image aspect ratio or not. Default: true.
36+
@param options.preferNativeRender - Prefer native terminal image protocols when available; set to false to force ANSI rendering. Default: true.
3637
@returns The ansi escape codes to display the image.
3738
3839
@example
@@ -51,6 +52,7 @@ declare const terminalImage: {
5152
width?: string | number;
5253
height?: string | number;
5354
preserveAspectRatio?: boolean;
55+
preferNativeRender?: boolean;
5456
}>) => Promise<string>;
5557

5658
/**
@@ -69,6 +71,7 @@ declare const terminalImage: {
6971
@param options.width - Optional: Custom image width. Can be set as percentage or number of columns of the terminal. It is recommended to use the percentage options.
7072
@param options.height - Optional: Custom image height. Can be set as percentage or number of rows of the terminal. It is recommended to use the percentage options.
7173
@param options.preserveAspectRatio - Optional: Whether to maintain image aspect ratio or not. Default: true.
74+
@param options.preferNativeRender - Prefer native terminal image protocols when available; set to false to force ANSI rendering. Default: true.
7275
@returns The ANSI escape codes to display the image.
7376
7477
@example
@@ -87,6 +90,7 @@ declare const terminalImage: {
8790
width?: string | number;
8891
height?: string | number;
8992
preserveAspectRatio?: boolean;
93+
preferNativeRender?: boolean;
9094
}>
9195
) => Promise<string>;
9296

index.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,12 @@ async function renderKitty(buffer, {width: inputWidth, height: inputHeight, pres
210210

211211
const terminalImage = {};
212212

213-
terminalImage.buffer = async (buffer, {width = '100%', height = '100%', preserveAspectRatio = true, isGifFrame = false} = {}) => {
213+
terminalImage.buffer = async (buffer, {width = '100%', height = '100%', preserveAspectRatio = true, isGifFrame = false, preferNativeRender = true} = {}) => {
214+
// If not using native terminal rendering, fallback to ANSI
215+
if (!preferNativeRender) {
216+
return render(buffer, {height, width, preserveAspectRatio});
217+
}
218+
214219
// Check for Kitty protocol support only if we're in an interactive terminal
215220
// and not in iTerm2 (which has its own protocol)
216221
// Note: We disable Kitty protocol for GIF frames as it doesn't work well with log-update

readme.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,13 @@ Default: `true`
8989

9090
Whether to maintain image aspect ratio or not.
9191

92+
##### preferNativeRender
93+
94+
Type: `boolean`\
95+
Default: `true`
96+
97+
Prefer native terminal image protocols when available; set to false to force ANSI rendering.
98+
9299
##### maximumFrameRate
93100

94101
**Only works for `terminalImage.gifBuffer` or `terminalImage.gifFile`**

0 commit comments

Comments
 (0)