[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 376
  • Last Modified:

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.
0
vanmilp
Asked:
vanmilp
1 Solution
 
Duncan RoeSoftware DeveloperCommented:
This looks like the old problem of the init string for your terminal switching to the alternate screen and switching back on completion. Nowadays I use "less -X" to avoid the termcap init/deinit strings - you could do the same programmatically or do what I used to do: modify the xterm terminfo entry not to switch screens, but that was a long time ago and I've lost the details. You'll need to find out what is the command that does the switch (must be documented for an xterm somewhere but I could never find it) and become horribly familiar with:
  man terminfo
  man infocmp
  man tic
0

Featured Post

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now