[Python-Dev] Updated curses module in CVS

Eric S. Raymond esr@thyrsus.com
Tue, 23 May 2000 20:47:50 -0400


Andrew M. Kuchling <akuchlin@mems-exchange.org>:
> Also, here's a list of ncurses functions that aren't yet supported;
> should I make adding them a priority.  (Most of them seem to be pretty
> marginal, except for the mouse-related functions which I want to add
> next.)
> 
> addchnstr addchstr chgat color_set copywin define_key del_curterm
> delscreen dupwin getmouse inchnstr inchstr innstr keyok mcprint
> mouseinterval mousemask mvaddchnstr mvaddchstr mvchgat mvcur
> mvinchnstr mvinchstr mvinnstr mmvwaddchnstr mvwaddchstr mvwchgat
> mvwgetnstr mvwinchnstr mvwinchstr mvwinnstr napms newterm overlay
> overwrite resetty resizeterm restartterm ripoffline savetty scr_dump
> scr_init scr_restore scr_set scrl set_curterm set_term setterm
> setupterm slk_attr slk_attr_off slk_attr_on slk_attr_set slk_attroff
> slk_attron slk_attrset slk_clear slk_color slk_init slk_label
> slk_noutrefresh slk_refresh slk_restore slk_set slk_touch tgetent
> tgetflag tgetnum tgetstr tgoto tigetflag tigetnum tigetstr timeout
> tparm tputs tputs typeahead ungetmouse use_default_colors vidattr
> vidputs waddchnstr waddchstr wchgat wcolor_set wcursyncup wenclose
> winchnstr winchstr winnstr wmouse_trafo wredrawln wscrl wtimeout

I think you're right to put the mouse support at highest priority.

I'd say napms() and the overlay/overwrite/copywin group are moderately
important.  So are the functions in the curs_inopts(3x) group -- when
you need those, nothing else will do.  

You can certainly pretty much forget the slk_* group; I only
implemented those for the sake of excruciating completeness.
Likewise for the mv* variants.  

Here's a function that ought to be in the Python wrapper associated with
the module:

def traceback_wrapper(func, *rest):
    "Call a hook function, guaranteeing curses cleanup on error or exit."
    try:
	# Initialize curses
	stdscr=curses.initscr()
	# Turn off echoing of keys, and enter cbreak mode,
	# where no buffering is performed on keyboard input
	curses.noecho() ; curses.cbreak()

	# In keypad mode, escape sequences for special keys
	# (like the cursor keys) will be interpreted and
	# a special value like curses.KEY_LEFT will be returned
        stdscr.keypad(1)

	# Run the hook.  Supply the screen window object as first argument
        apply(func, (stdscr,) + rest)

	# Set everything back to normal
	stdscr.keypad(0)
	curses.echo() ; curses.nocbreak()
	curses.endwin()		 # Terminate curses
    except:
	# In the event of an error, restore the terminal
	# to a sane state.
	stdscr.keypad(0)
	curses.echo() ; curses.nocbreak()
	curses.endwin()
	traceback.print_exc()	   # Print the exception

(Does this case mean, perhaps, that the Python interper ought to allow
setting a stack of hooks to be executed just before traceback-emission time?)

I'd also be willing to write a Python function that implements Emacs-style
keybindings for field editing, if that's interesting.
-- 
		<a href="http://www.tuxedo.org/~esr">Eric S. Raymond</a>

Don't think of it as `gun control', think of it as `victim
disarmament'. If we make enough laws, we can all be criminals.