Hacker News new | ask | show | jobs
by Sean1708 2304 days ago
> Somehow this works even across SSH connections…

The source code[1] is quite simple to read (as long as you know Bash) but basically imgcat prints a special OSC[2] sequence (some bytes that tell the terminal to do something special) to stdout followed by the image data which iTerm then handles specially because of the OSC sequence, as far as SSH knows they're just some bytes that it needs to send (no different than running normal cat on a text file). You can kind of think of this as the opposite of what bracketed paste[3] does, in bracketed paste the terminal tells the program to treat some data specially but with imgcat the program tells the terminal to treat some data specially.

[1]: https://iterm2.com/utilities/imgcat

[2]: https://en.wikipedia.org/wiki/ANSI_escape_code#Escape_sequen...

[3]: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h2-B...