[Tutor] curses on linux

lonetwin lonetwin@yahoo.com
Tue Jun 24 02:48:01 2003


Hi,
    I plan to write a little app. on linux that uses the curses module. 
Here's what I'd like to do:

a) Start up my application. (ie: all the initscr & stuff)
b) Open another curses based application "embedded" within mine (actually
I'm planning to fire-up the 'links' browser). By embedded I mean either it
is displayed in one sub-window/pad on the screen, or it is displayed as it
normally should with a key binding that'll allow me to switch between the
embedded app and mine.
c) I should be able to move between these two apps.

     However, I can't figure out how to do this. I tried using
curses.def_[prog|shell]_mode, and curses.reset_[prog|shell]_mode, but that
doesn't seem to work. From the Ncurses faq I learnt
[ http://dickey.his.com/ncurses/ncurses.faq.html#handle_piping ]
---------------------------------------------
Redirecting I/O to/from a Curses application
In principle, you should be able to pipe to/from a curses application.
However, there are caveats:

    * Some (very old) curses implementations did not allow redirection of
the screen. Ncurses, like Solaris curses, consistently writes all output to
the standard output. You can pipe the output to a file, or use tee to show
the output while redirecting.
    * Ncurses obtains the screen size by first using the environment
variables LINES and COLS (unless you have disabled it with the use_env
call), then trying to query the output file pointer, and then (finally) the
terminal description. If you are redirecting output, then a query based on
the file pointer will always fail, resulting in the terminal description's
size.
* Similarly, you can redirect input to an ncurses application. However, I
have observed that the use of setvbuf (for better output buffering)
interferes with the use of stream I/O on GNU/Linux (and possibly other
platforms). Invoking setvbuf may (depending on the implementation) cause
buffered stream input to be discarded. Ncurses does not use buffered input,
however you may have an application that mixes buffered input with a curses
session.
---------------------------------------------
    How do I translate that to python ??
Right now, I've cooked up something ugly using the pty module (pty.spawn()
function). However, it's far from what I'd like to do.
    I'd post the code if anyone is interested, I didn't do it here, 'cos
it's kinda big.

any suggestions ??

Peace
Steve

An idealist is one who helps the other fellow to make a profit.
                -- Henry Ford