views:

67

answers:

2

I'm making a program that displays some info in ncurses, and then opens vim (using system) to allow the user to edit a file. After vim is exited, though, the ncurses screen won't redraw. refresh and wrefresh don't do anything, resulting in the complete trashing of my beautiful menu.

So, I get sent back to the command line. The menu items redraw when I move to them. Moving around a bit results in something that looks like this:

Tragedy

As you can see, I no longer am in my pretty ncurses environment,.

I could tear down ncurses completely and set things up again, but then some stuff (like menu position) is not preserved.

How do I do this correctly? Is there a better way to call some external program and return here gracefully?

A: 

Separate your program state from the curses state.

The only clean way I know of is to stop and restart curses entirely. If your program has a clean notion of its internal state (as it should), then it should be easy to go back to the same position.

Good luck!

vlabrecque
+1  A: 

I've never had to restart curses entirely.

what if you do something like

def_prog_mode() then endwin()

execute system call

and refresh() should restore it

Tree77
Thanks! This seems to work, but every now and then I get back to my curses UI and none of my keystrokes register. So I have to kill the program. Any ideas?
ty
how do you init ncurses? initscr(); /* initialize the curses library */ keypad(stdscr, TRUE); /* enable keyboard mapping */ nonl(); /* tell curses not to do NL->CR/NL on output */ cbreak(); /* take input chars one at a time, no wait for \n */ noecho(); /* don't echo input */Is something changing the input method? you could call cbreak() when you return
Tree77
I'm doing all the above, still no luck unfortunately.
ty
This seems similar to the problem here: http://stackoverflow.com/questions/1189708/ncurses-to-external-shell-and-back-messing-with-keys But calling keypad(win, 1) doesn't help.
ty
sorry flat out of ideas for loss of keystrokes
Tree77