Solved

How to properly end curses-session in xterm.

Posted on 2006-11-27
3
359 Views
Last Modified: 2010-04-21
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
Comment
Question by:vanmilp
3 Comments
 
LVL 34

Accepted Solution

by:
Duncan Roe earned 500 total points
ID: 18057787
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever been frustrated by having to click seven times in order to retrieve a small bit of information from the web, always the same seven clicks, scrolling down and down until you reach your target? When you know the benefits of the command l…
The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question