Wrapper function that initializes curses and calls another function, restoring normal keyboard/screen behavior on error. The callable object 'func' is then passed the main window 'stdscr' as its first argument, followed by any other arguments passed to wrapper().
(func, /, *args, **kwds)
| 57 | # you can read the resulting traceback. |
| 58 | |
| 59 | def wrapper(func, /, *args, **kwds): |
| 60 | """Wrapper function that initializes curses and calls another function, |
| 61 | restoring normal keyboard/screen behavior on error. |
| 62 | The callable object 'func' is then passed the main window 'stdscr' |
| 63 | as its first argument, followed by any other arguments passed to |
| 64 | wrapper(). |
| 65 | """ |
| 66 | |
| 67 | try: |
| 68 | # Initialize curses |
| 69 | stdscr = initscr() |
| 70 | |
| 71 | # Turn off echoing of keys, and enter cbreak mode, |
| 72 | # where no buffering is performed on keyboard input |
| 73 | noecho() |
| 74 | cbreak() |
| 75 | |
| 76 | # In keypad mode, escape sequences for special keys |
| 77 | # (like the cursor keys) will be interpreted and |
| 78 | # a special value like curses.KEY_LEFT will be returned |
| 79 | stdscr.keypad(1) |
| 80 | |
| 81 | # Start color, too. Harmless if the terminal doesn't have |
| 82 | # color; user can test with has_color() later on. The try/catch |
| 83 | # works around a minor bit of over-conscientiousness in the curses |
| 84 | # module -- the error return from C start_color() is ignorable, |
| 85 | # unless they are raised by the interpreter due to other issues. |
| 86 | try: |
| 87 | start_color() |
| 88 | except _curses.error: |
| 89 | pass |
| 90 | |
| 91 | return func(stdscr, *args, **kwds) |
| 92 | finally: |
| 93 | # Set everything back to normal |
| 94 | if 'stdscr' in locals(): |
| 95 | stdscr.keypad(0) |
| 96 | echo() |
| 97 | nocbreak() |
| 98 | endwin() |
nothing calls this directly
no test coverage detected
searching dependent graphs…