timg image and video viewer in hterm using the iTerm2 graphics extension

143 views
Skip to first unread message

Henner Zeller

unread,
Mar 14, 2021, 5:01:31 AM3/14/21
to chromiu...@chromium.org

Hi,

timg ( http://timg.sh/ ) is an image and video viewer for terminals with a bunch of useful features to show images in a terminal. For simple terminals, it uses block characters to show images. If a terminal supports the iTerm2 or Kitty image protocols it can use that to show high-resolution images.

I just read somewhere that hterm also supports the iTerm2 protocol; so now I made timg also work with hterm :)
I had to do some work-arounds for limitations [1], but overall, it is pretty promising.

To use you have to supply the -pi option to timg to output an image using the high-res iTerm2 mode:

   timg -pi some-image.jpg


Not all features of timg work due to limitations of hterm, but I hope they might be implemented in the future ? Some look potentially easy to implement:
  •  Placing images only seems to work on the left of the terminal window. Moving the cursor to a different character cell to the right before showing an image will still only show the image flush to the left. This means that timg --center and --grid features don't work.
  •  To play animations and videos, timg would need to know the size of a character cell in pixels. For that,  it uses a TIOCGWINSZ ioctl. Alas, the window size in pixels is not returned. Animations and videos still work in the regular Unicode block modes though (using -pq), just not in high resolution iTerm2 image mode.
  • The terminal can not be queried with the somewhat common \033[>q CSI, so timg can not auto-detect if the terminal likely supports iTerm2 graphics. The user has to provide -pi option ( or long --pixelation=iterm2).
    Question to the developers: is there a reliable way for a program to figure out if it runs in a hterm ?
In general this is already exciting. I often inspect images on a remote server on the shell with timg, and this is another terminal emulator that I can use now :)

Thanks to the hterm team to support the high-resolution image feature.
timg-in-hterm.png

Mike Frysinger

unread,
Mar 15, 2021, 2:04:09 AM3/15/21
to Henner Zeller, chromium-hterm
if you have specific issues (and it sounds like you do), could you file them in our tracker ?  if you have Secure Shell installed already, you can use the "Send Feedback" link.  we'd want one report per issue.

wrt positioning, it is correct that hterm doesn't follow the cursor position.  that was a bit intentional ... it's unclear whether that's better, especially when the sizing+alignment options are specified.  align={left|center|right} should work, and i just tested the center setting and it seemed fine.

i keep meaning to register TERM=hterm in ncurses, but haven't gotten to it.  the terminfo.src file is pretty dense :/.
-mike

--
You received this message because you are subscribed to the Google Groups "chromium-hterm" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-hter...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-hterm/CAEQqtJwNYdzH99soXCn4y8HV-bpfHfh6%2B0xTqNF_bW5r_7Lsag%40mail.gmail.com.

Henner Zeller

unread,
Mar 15, 2021, 2:34:00 AM3/15/21
to Mike Frysinger, chromium-hterm
On Sun, 14 Mar 2021 at 23:04, Mike Frysinger <vap...@chromium.org> wrote:
if you have specific issues (and it sounds like you do), could you file them in our tracker ?  if you have Secure Shell installed already, you can use the "Send Feedback" link.  we'd want one report per issue.

Sounds good, will do.
 
wrt positioning, it is correct that hterm doesn't follow the cursor position.  that was a bit intentional ... it's unclear whether that's better, especially when the sizing+alignment options are specified.  align={left|center|right} should work, and i just tested the center setting and it seemed fine.

timg allows for more advanced placement, such as arbitrary grid sizes, which would need the fine-grained control of where images are placed

multi-column-timg.png
 

i keep meaning to register TERM=hterm in ncurses, but haven't gotten to it.  the terminfo.src file is pretty dense :/.

Just some identification returned from a well-known CSI might be sufficient. In particular since terminfo queries were not really meant for 'is this terminal supporting images' kind of things. Most terminals identify as xterm-256color anyway these days in TERM.

The following seems to be pretty common. If you try the following in an xterm or iTerm2 for instance, you'll get back some response that helps identify
    echo -e "\033[>q"

Something like that I use to identify iTerm2 and wezTerm for detecting the iTerm2 graphics capability.

-henner
Reply all
Reply to author
Forward
0 new messages