Solved

How to properly end curses-session in xterm.

Posted on 2006-11-27
3
354 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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

The purpose of this article is to fix the unknown display problem in Linux Mint operating system. After installing the OS if you see Display monitor is not recognized then we can install "MESA" utilities to fix this problem or we can install additio…
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…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

762 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now