ยปCore Development>Code coverage>Lib/curses/wrapper.py

Python code coverage for Lib/curses/wrapper.py

#countcontent
1n/a"""curses.wrapper
2n/a
3n/aContains one function, wrapper(), which runs another function which
4n/ashould be the rest of your curses-based application. If the
5n/aapplication raises an exception, wrapper() will restore the terminal
6n/ato a sane state so you can read the resulting traceback.
7n/a
8n/a"""
9n/a
10n/aimport curses
11n/a
12n/adef wrapper(func, *args, **kwds):
13n/a """Wrapper function that initializes curses and calls another function,
14n/a restoring normal keyboard/screen behavior on error.
15n/a The callable object 'func' is then passed the main window 'stdscr'
16n/a as its first argument, followed by any other arguments passed to
17n/a wrapper().
18n/a """
19n/a
20n/a try:
21n/a # Initialize curses
22n/a stdscr = curses.initscr()
23n/a
24n/a # Turn off echoing of keys, and enter cbreak mode,
25n/a # where no buffering is performed on keyboard input
26n/a curses.noecho()
27n/a curses.cbreak()
28n/a
29n/a # In keypad mode, escape sequences for special keys
30n/a # (like the cursor keys) will be interpreted and
31n/a # a special value like curses.KEY_LEFT will be returned
32n/a stdscr.keypad(1)
33n/a
34n/a # Start color, too. Harmless if the terminal doesn't have
35n/a # color; user can test with has_color() later on. The try/catch
36n/a # works around a minor bit of over-conscientiousness in the curses
37n/a # module -- the error return from C start_color() is ignorable.
38n/a try:
39n/a curses.start_color()
40n/a except:
41n/a pass
42n/a
43n/a return func(stdscr, *args, **kwds)
44n/a finally:
45n/a # Set everything back to normal
46n/a stdscr.keypad(0)
47n/a curses.echo()
48n/a curses.nocbreak()
49n/a curses.endwin()