Skip to content

Conversation

endernoke
Copy link
Contributor

@endernoke endernoke commented Sep 17, 2025

Added the size parameter to the image escape sequence to have wider compatibility with different terminal emulators that implements iTerm2 inline images protocol

From iTerm2's specs:

Key Description of value
name   base-64 encoded filename. Defaults to "Unnamed file".
size   File size in bytes. Optional; this is only used by the progress indicator.
width Width to render. See notes below.
height Height to render. See notes below.
preserveAspectRatio If set to 0, then the image's inherent aspect ratio will not be respected; otherwise, it will fill the specified width and height as much as possible without stretching. Defaults to 1.
inline If set to 1, the file will be displayed inline. Otherwise, it will be downloaded with no visual representation in the terminal session. Defaults to 0.

This enables images to be displayed in terminal emulators with non-standard protocol checks, e.g. xterm.js, that requires the size parameter to be set.

To test:

  1. In VS Code, enable terminal.integrated.enableImages and terminal.integrated.gpuAcceleration
  2. run this inside the integrated terminal, which uses xterm.js:
import AnsiEscapes from "ansi-escapes";
import fs from "fs";

const image = fs.readFileSync("fixture.jpg");
console.log(AnsiEscapes.image(image));

@sindresorhus
Copy link
Owner

size File size in bytes. Optional; this is only used by the progress indicator.

It's marked as optional.

This enables images to be displayed in terminal emulators with stricter protocol checks, e.g. xterm.js

That's not stricter protocol check. That's incorrect protocol checks if it requires size.

@endernoke
Copy link
Contributor Author

size File size in bytes. Optional; this is only used by the progress indicator.

It's marked as optional.

This enables images to be displayed in terminal emulators with stricter protocol checks, e.g. xterm.js

That's not stricter protocol check. That's incorrect protocol checks if it requires size.

Yes you are right, I'll edit the comment above

But I think it is still beneficial to add size as:

  • it is allowed in the specs
  • the library will have better compatibility across terminals that may have non-standard implementation
  • it works (to the best of my knowledge) on all existing terminals that support iterm2 IIP

@sindresorhus
Copy link
Owner

While it's a simple change, I think you are trying to fix this in the wrong place. Now everyone has to work around xterm.js' incorrect implementation of the protocol. I think it would be better to fix this at the source, in xterm.js.

@endernoke
Copy link
Contributor Author

I just came across a related issue: xtermjs/xterm.js#5326 (comment).

In an older sequence version, the size notion was mandatory.

I’m unable to independently verify this statement, but if it’s accurate, including size might improve backward compatibility with older iTerm2 versions and other terminal emulators.

While it's a simple change, I think you are trying to fix this in the wrong place. Now everyone has to work around xterm.js' incorrect implementation of the protocol. I think it would be better to fix this at the source, in xterm.js.

I understand your perspective. If this change doesn't align with the project's philosophy, feel free to close the PR. I’m happy to adjust or explore alternatives if needed.

@sindresorhus
Copy link
Owner

Alright. Doesn't seem like xterm.js plans to change that, so I guess we will.

@sindresorhus sindresorhus merged commit b739b18 into sindresorhus:main Sep 17, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants