Display images in console (curses)?

6,357

Solution 1

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.

Solution 2

In principle, perhaps. But none of the necessary work has been done. ncurses is based on POSIX termios, and framebuffers have little to do with that.

PDCurses was ported to use SDL (Simple Direct Media), so it's "doable".

Share:
6,357

Related videos on Youtube

f1rstsurf
Author by

f1rstsurf

Quite frankly, even if the choice of C were to do nothing but keep the C++ programmers out, that in itself would be a huge reason to use C. In other words: the choice of C is the only sane choice. I know Miles Bader jokingly said "to piss you off", but it's actually true. I've come to the conclusion that any programmer that would prefer the project to be in C++ over C is likely a programmer that I really would prefer to piss off, so that he doesn't come and screw up any project I'm involved with. The only way to do good, efficient, and system-level and portable C++ ends up to limit yourself to all the things that are basically available in C. And limiting your project to C means that people don't screw that up, and also means that you get a lot of programmers that do actually understand low-level issues and don't screw things up with any idiotic "object model" crap. So I'm sorry, but for something like git, where efficiency was a primary objective, the "advantages" of C++ is just a huge mistake. The fact that we also piss off people who cannot see that is just a big additional advantage. -- Linus Torvalds

Updated on September 18, 2022

Comments

  • f1rstsurf
    f1rstsurf almost 2 years

    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?

  • f1rstsurf
    f1rstsurf over 8 years
    I was just about to mail you to ask, but you beat me to it. Yes, I guess the remote aspect of ncurses precludes using the buffer; it would have to be some kind of purely local console windowing system, I guess.