Skip to main content
Welcome guest. | Register | Login | Post

project idea: grcurses

4 replies [Last post]
tbuitenh's picture
Offline
Joined: 2005-12-21

Here's the situation: I'm writing a program of which the user interface is most easily implemented in (n)curses. At the moment it's not functional yet, but I have to keep looking a few steps ahead to make sure I don't run into trouble later...
Once it becomes functional, I would like to give it a better looking user interface, probably SDL (for portability), maybe also SVGALib.

When I will write the second UI, there are two things I could do:
- write the user interface all over again
- re-implement the ncurses functions I use on top of the graphics library, changing some of them to make the result look better (eg border() could draw a nice 3d border instead of line characters). Also add some curses-like functions that can display images or gradients or whatnot behind text, and add dummies with the same names to the ncurses version of my program.

I like the second option, so that is what I probably will do. But thinking another step further... wouldn't it be nice if my program had only one version, which first tried to use SDL, and if that failed would fall back to ncurses?

I think if I would create that functionality, it might be useful for other programmers too, so I might make a full implementation of curses and separate it into a library.

Does anyone here think they would like to have a library with which:
- existing curses based apps can run on X without an xterm, and depending on the app possibly also on ms windows without cygwin?
- one can make prettier than ncurses apps that will still work but look as ugly as ncurses when only a text console is available?

Since it would be only a just for fun project I'm not asking if it would be useful to you in the near future, just asking if it would be useful for programs you might write sometime in the less near future.

If there is demand for this, I'll make sure that my code will be useful for other programs, otherwise I might be lazy and make it inflexible, incomplete, and only useful for me.

Offline
Joined: 2006-03-28
This could be interesting,

This could be interesting, but this I guess you should offer the option to override automatic detection of SDL or ncurses is used.

tbuitenh's picture
Offline
Joined: 2005-12-21
That's a simple matter of

That's a simple matter of making the initialization functions for the different backends available.

/* grc_backend.h */
typedef void grc_window; /* this is okay, windows are always passed as pointers */
/* grcurses.h */
#include <grc_backend.h>
...
#define WINDOW grc_window
...
/* all three below are available to application programmers */
WINDOW * initscr_ncurses(void);
WINDOW * initscr_sdl(void);
WINDOW * initscr(void);
...
/* grc_ncurses.c */
#include <grc_backend.h>
#include <ncurses.h>
...
grc_window * initscr_ncurses(void) {
  return (grc_window *) initscr(); /* this is initscr from ncurses, not ours */
}
...
/* grcurses.c */
...
WINDOW * initscr(void) {
  char * preferred;
  if ((preferred = getenv("GRCBACKEND"))) {
  ...
    return ...
  ...
  }
  return initscr_sdl() || initscr_ncurses();
}
...
libervisco's picture
Offline
Joined: 2006-05-04
Making ncurses program not

Making ncurses program not necessarily tied to the command line sounds like something I would like. It would also save some work to distros who tend to make exact GUI equivalents to certain ncurses configuration utilities.

tbuitenh's picture
Offline
Joined: 2005-12-21
Tied to the command line?

Tied to the command line? You mean tied to the console or a terminal emulator.

I never looked into their code, but I think the distros have simplified widget set libraries that have both a GUI and a ncurses backend, their user interfaces probably aren't using ncurses directly. However if anyone wants to create a new distro, this could be useful.

Another good use is running curses-dependent programs on operating systems that don't have a decent text mode. Although maybe helping ms windows by bringing lots of little nice apps to it is not a good use Laughing out loud .

There's a catch: there's only so much features not normally supported by text terminals that one can extend the curses API with. Proportional fonts, or even different font sizes, would be problematic. Using an image as a background instead of a color is doable (would fall back to a color when using the original ncurses as a backend), adding pretty borders to rectangles of characters can be done too (will simply not be shown), but anything that goes further than that can't be done. On the other hand, with clever use of images and borders, you can make a (G)UI that doesn't look like a text terminal at all.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.