When working with plotting like gnuplot
or ggplot2
or just navigating your
filesystem on the command line, it would be nice to be able to view bitmap or
vector graphics easily.
This is all for the ideal of hybrid GUI TUI interface!!
However this turns out to be difficult. However I found pretty much 5 ways to do this.
If your terminal emulator can handle SIXEL graphics, it can display SIXEL graphics inline: https://github.com/saitoha/libsixel (you can convert anything to SIXEL including SVG)
This would be most preferable, as it was a protocol designed to show graphics on the terminal. Which means it can work over the network (like SSH).
ASCII armor your images! This is the most portable. Use cacaview
or hiptext
.
- https://github.com/jart/hiptext - this is better than cacaview
You have to use the latest w3m
with support for this compiled in. Then you need
a terminal emulator that w3mimgdisplay
supports. I've only found xterm and
gnome-terminal to support this. It's basically a hack, and it still relies on X.
That is the images are displayed inline inside the terminal emulator, but it's
actually terminal graphics, it's just overlays X graphics on top. So it cannot be
used over SSH.
Ranger makes use of this to allow previewing of images when navigating the filesystem.
Ok this isn't really using the terminal emulator, but the workflow is pretty solid. Basically do this:
# scale-down scales down large images
# auto-zoom scales up small images
# keep-zoom-vp is required if there very different sized images, we don't want the window jumping up and down
# magick-timeout allows using imagemagick to lookup SVG files
alias feh='feh \
--scale-down \
--auto-zoom \
--borderless \
--image-bg black \
--draw-filename \
--draw-tinted \
--keep-zoom-vp \
--magick-timeout 1'
cat image.jpeg | feh -
feh ./directory/with/images
It works best using a tiling windows manager. You can hook your windows manager
like XMonad to display feh
windows in a floating manner. Otherwise, it's going
to take focus away from your command prompt, and that's annoying.
-- excerpt from my xmonad.hs
matrixHooks =
composeAll [
className =? "feh" --> doCenterFloat
]
You can also run such a command on dmenu
prompt. Allowing you to fill up the
entire screen with multi window images.
feh
is pretty powerful, it has lots of keyboard shortcuts that you can use
once you have the image opened up. Note that the --magick-timeout
option is
only useful if you have imagemagick
, it allows you to view SVG files as well.
Like Emacs or Jupyter or iTerm2 or BlackScreen.
Or wait for some epic revolution to terminal emulators that derives from the conversational UI trend.