MCPcopy Create free account
hub / github.com/RT-Thread/env-windows / wrapper

Function wrapper

tools/python-3.11.9-amd64/Lib/curses/__init__.py:63–101  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 2

initscrFunction · 0.85
start_colorFunction · 0.85

Tested by

no test coverage detected