views:

742

answers:

2

The title is a bit more specific than my actual goal:

I have a command-line program which uses GNU Readline, primarily for command history (i.e. retrieving previous commands using up-arrow) and some other niceties. Right now the program's output appears interspersed with the user's input, which sometimes is OK but the output is asynchronous (it comes via a network connection in response to the input commands), and that gets annoying sometimes (e.g. if lines are output when the user is typing new input).

I'd like to add a feature to this program: a separate "window" for the output. I thought about using ncurses for this. But it appears from the ncurses FAQ that the two libraries are not easy to use together.

I might consider using Editline or tecla instead of Readline, but it's not clear to me if either of those will solve my problem. I'd also consider using something other than ncurses, including a library which provides both kinds of functionality (text-mode windows and command history), but I don't know what might be best.

Oh, and support for colored text might get bonus points. I suspect I may be able to do that with Readline, so maybe it's a separate concern, but if a solution to my problem also makes it easy to add a bit of color to the output, so much the better.

I'm using Ubuntu Hardy (Linux 2.6).

+1  A: 

I have done some searching, and it seems like you are out of luck.

For ncurses alternatives there are SLang, Newt and Turbo Vision. Slang is much more than just screen handling and thus more complex, but maybe it can be used for your purpose?. Newt uses the screen handling and is much simpler, but too simple and single-threaded-mode for your purpose I think.

Turbo vision is the text mode graphics library from Borland, used by all their tools in the late 80s/early 90s. Borland released the source code when the marked for that kind of thing diminished, and there is now a port for linux (side note, this project seems to have written its own turbo vision implementation). That port is not dead (there have been some cvs updates this year which compiled fine (the older releases did not)), but none of the TV examples I found were up to date and I did only got a few of them to compile before giving up on the rest. This is a bit of a shame, because TV was a lovely environment to use. TV is btw C++ (and I assume you are using C?).

For an alternative to readline, there is libkinput, which maybe works together with ncurses (it says it can use ncurses' terminfo. but I am not sure if that means that it can co-exists together with ncurses usage)?

Maybe one option is to run readline "externally" to your ncurses program using rlwrap?

hlovdal
+1  A: 

I've achieved what you've described in a program of mine:

http://dpc.ucore.info/lab:xmppconsole

The following is the file handling io:

http://github.com/dpc/xmppconsole/blob/master/src/io.c

dpc.ucore.info