Link to home
Start Free TrialLog in
Avatar of vanmilp
vanmilp

asked on

How to properly end curses-session in xterm.

I run a console-app, written in curses, called trough Python from a terminal. This app. also calls some functions that show a Yes/No-dialog, DropDownbox, Edit-entry, all written in curses. All these functions run fine from within the app.

However, those functions also need to be called from a terminal. That's were things go wrong.

When calling either of these functions, for example  the YesNo-dialog, the entire screen gets blank, all text that is on the terminalscreen disappears, only my YesNo-dialog is present. When I leave the dialog, the screen with text reappears. But I would like to have the YesNo-dialog popup on top of the terminal-screen, so I can still see what's going on. Second thing that goes wrong is that, after that YesNo-dialog closes, the terminal doesn't recognize any linefeeds and tabs. When I want to print text  after calling the YesNo-dialog, all text gets wrapped up. I have to explicitly add a chr(13) to each item to have it nicely printed on the left side of the screen.
It looks like curses is initializing the total screen, taking over full controle, and, after ending, doesn't return correctly back to the terminal.

My Linux-version is Ubuntu Breezer.

These are my Init and InitOut-sections:
def Init():
    '''
    Initialize environment
    '''
    curses.initscr()
    curses.start_color()
    curses.init_pair(1, curses.COLOR_YELLOW, curses.COLOR_BLACK)
    curses.init_pair(2, curses.COLOR_WHITE, curses.COLOR_BLUE)
    curses.init_pair(3, curses.COLOR_WHITE, curses.COLOR_MAGENTA)
    curses.init_pair(4, curses.COLOR_RED, curses.COLOR_WHITE)
    curses.init_pair(5, curses.COLOR_BLACK, curses.COLOR_WHITE)

# Turn off echoing of keys, and enter cbreak mode,
# where no buffering is performed on keyboardinput
    curses.noecho() ; curses.cbreak() ; curses.curs_set(0) ;
    stdscr.keypad(False)

def InitOut():
    curses.nocbreak()
    curses.echo()
    curses.doupdate()
    curses.endwin()

Am I missing something ???

I can't use the Dialogs.py, because the whole app. has to be written in curses by ourselves.
ASKER CERTIFIED SOLUTION
Avatar of Duncan Roe
Duncan Roe
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial