Display images in console (curses)

consoleimagesncurses

What approach can be used to display an image in a console (no X windows)?

For example, I can use curses/ncurses to divide a console into different panes, but in some situations I would like to display an image in one of the panes. Having to switch to X, and assume all that baggage and overhead just to display one image seems like complete overkill. I DO NOT need a windowing system or mouse handling. I just need to put an image on screen.

The problem I have with X Windows is that it is a "windowing" system, whereas I prefer a frame-based approach (no overlaps) like curses. (I think the whole "window" paradigm invented by Xerox Parc which conceives of "windows" as an analog of pieces of paper on a desk that lay on top of each other is idiotic.)

In theory this should be possible, because, as I understand it, consoles are not actually really consoles anymore. They are emulated consoles and they actually are implemented with a full screen resolution which has a pixel-by-pixel control. The question is just how can this emulator be extended to support limited display of raster images on the console?

One possible solution, albeit Linux specific, is the Linux Framebuffer functionality (fbdev). Is it possible to get this to play nice with ncurses?

Best Answer

The "emulated consoles" are system-specific, as you understand with your reference to fbdev. Furthermore, they are generally integrated into the kernel, so trying to modify them directly would require modifying the kernel, which is certainly more 'overkill' than putting up with X.

You could use fbdev directly, or write something based on SDL like Thomas Dickey suggests, but as he said, none of the necessary work has been done, and the amount of work that represents should not be underestimated.

But while most of the common desktop environments are fairly heavy-weight, X itself is not (by any remotely modern standards). If you have an app that is primarily text-based, but you need to put up an image every now and then, consider using X without a desktop environment. How? Use startx or a custom script to start the X server and an xterm (or your terminal emulator of choice), full-screen, with no window manager (or find one of the alternative ultra-lightweight WMs). Hide the mouse cursor if you want. Then, from within your text-mode program, you can start and stop lightweight image-displaying X clients at specified locations on the screen, and remove them under program control. You can resize the xterm or just accommodate the fact that part of your text screen will be obscured. Of course, there are an unlimited number of variations on this theme, but you get the idea.

I used to use X on Unix machines with under 4Mb of RAM (not Gb), so it's not necessary for X to be bloated. As a beneficial side-effect, you gain platform portability (you can potentially target anything with an X server) and the ability to run remotely.

Related Question