have you checked the python curses howto already? I have written a curses wrapper for one of my projects. Maybe it can help showing what steps you need. I've been using curses a lot for my own projects so feel free to ask me if there's something you want to know. The python curses library is mostly just a wrapper around calls to the ncurses system library. Documentation for that library or ports in other languages will likely help you in python too. Answer from troido on reddit.com
🌐
Python documentation
docs.python.org › 3 › howto › curses.html
Curses Programming with Python — Python 3.14.3 documentation
Once the callable returns, wrapper() will restore the original state of the terminal. The callable is called inside a try…except that catches exceptions, restores the state of the terminal, and then re-raises the exception. Therefore your terminal won’t be left in a funny state on exception and you’ll be able to read the exception’s message and traceback. Windows are the basic abstraction in curses.
🌐
Python
docs.python.org › 3 › library › curses.html
curses — Terminal handling for character-cell displays
Initialize curses and call another callable object, func, which should be the rest of your curses-using application. If the application raises an exception, this function will restore the terminal to a sane state before re-raising the exception and generating a traceback. The callable object func is then passed the main window ‘stdscr’ as its first argument, followed by any other arguments passed to wrapper().
🌐
DevDungeon
devdungeon.com › content › curses-programming-python
Curses Programming in Python | DevDungeon
June 10, 2019 - To accomodate this, the curses package provides a function that can wrap your whole application that way it can handle restoring things to a sane state. To use the wrapper, create a function that takes one argument: the screen.
🌐
Reddit
reddit.com › r/roguelikedev › any python/curses resources?
r/roguelikedev on Reddit: Any Python/Curses resources?
May 10, 2021 -

I know curses is generally disliked around here, and tcod is recommended. I've tried to get tcod working on two operating systems though, and couldn't get it to work on either. I haven't tried really hard though, because curses really appeals to me, both by being the traditional library used for most of the roguelikes I played growing up, and also because of the small footprint when it comes to system resources.

There aren't many Python/Curses resources out there. I've found a few non-roguelike-specific tutorials on youtube, the Rogue Detective source, and this non-functional algorithm. I'm pretty sure this is enough for me to cobble together something playable. I'm just curious whether there are better methods I could be using.

🌐
Beautiful Soup
tedboy.github.io › python_stdlib › generated › generated › curses.wrapper.html
curses.wrapper() — Python Standard Library
Wrapper function that initializes curses and calls another function, restoring normal keyboard/screen behavior on error.
🌐
GitHub
github.com › enthought › Python-2.7.3 › blob › master › Lib › curses › wrapper.py
Python-2.7.3/Lib/curses/wrapper.py at master · enthought/Python-2.7.3
import curses · · def wrapper(func, *args, **kwds): """Wrapper function that initializes curses and calls another function, restoring normal keyboard/screen behavior on error.
Author   enthought
🌐
Python
docs.python.org › 2.0 › lib › module-curses.wrapper.html
6.14 curses.wrapper -- Terminal handler for curses programs
Wrapper function that initializes curses and calls another function, func, restoring normal keyboard/screen behavior on error.
Find elsewhere
🌐
GitHub
gist.github.com › claymcleod › b670285f334acd56ad1c
Python curses example · GitHub
import curses def draw_menu(stdscr): k = 0 kw = 0 kk = "" height, width = stdscr.getmaxyx() min_x_keystr = width - 1 min_x_wkeystr = width - 1 min_x_kkeystr = width - 1 cursor_x = 0 cursor_y = 0 # Clear and refresh the screen for a blank canvas stdscr.clear() stdscr.refresh() # Start colors in curses curses.start_color() curses.init_pair(1, curses.COLOR_CYAN, curses.COLOR_BLACK) curses.init_pair(2, curses.COLOR_RED, curses.COLOR_BLACK) curses.init_pair(3, curses.COLOR_BLACK, curses.COLOR_WHITE) # Loop where k is the last character pressed while (k != ord('q')): # Initialization #stdscr.clear()
🌐
PyPI
pypi.org › project › Uni-Curses
Uni-Curses · PyPI
A universal Curses wrapper for Python on Windows, FreeBSD, Linux, and Mac OS X, with syntax close to the original NCurses.
      » pip install Uni-Curses
    
Published   Jul 05, 2024
Version   3.1.2
🌐
OMZ Software
omz-software.com › editorial › docs › howto › curses.html
Curses Programming with Python — Editorial Documentation
In Python you can avoid these complications and make debugging much easier by importing the module curses.wrapper. It supplies a wrapper() function that takes a callable. It does the initializations described above, and also initializes colors if color support is present.
🌐
Python
docs.python.org › 3.12 › howto › curses.html
Curses Programming with Python — Python 3.12.12 documentation
Once the callable returns, wrapper() will restore the original state of the terminal. The callable is called inside a try…except that catches exceptions, restores the state of the terminal, and then re-raises the exception. Therefore your terminal won’t be left in a funny state on exception and you’ll be able to read the exception’s message and traceback. Windows are the basic abstraction in curses.
🌐
DevTut
devtut.github.io › python › basic-curses-with-python.html
Python - Basic Curses with Python
main(scr, *args): # -- Perform an action with Screen -- scr.border(0) scr.addstr(5, 5, 'Hello from Curses!', curses.A_BOLD) scr.addstr(6, 5, 'Press q to close this screen', curses.A_NORMAL) while True: # stay in this loop till the user presses 'q' ch = scr.getch() if ch == ord('q'): curses.wrapper(main)
🌐
Medium
medium.com › @mike-dresser › curses-and-other-dirty-words-996a24df7c1f
Curses, and Other Dirty Words. When it comes to getting quick and… | by Mike Dresser | Medium
March 28, 2024 - After invoking initscr() there are a handful of other commands we’ll need to set up just to get running, to say nothing exiting cleanly, terminating all the running processes, and restoring the contents of the user’s terminal to their state before running your code. Luckily, curses provides us with a shortcut: the wrapper().
🌐
Python
docs.python.org › 3.8 › howto › curses.html
Curses Programming with Python — Python 3.8.20 documentation
from curses import wrapper def main(stdscr): # Clear screen stdscr.clear() # This raises ZeroDivisionError when i == 10.
🌐
Python
docs.python.org › 3.10 › howto › curses.html
Curses Programming with Python — Python 3.10.16 documentation
from curses import wrapper def main(stdscr): # Clear screen stdscr.clear() # This raises ZeroDivisionError when i == 10.
🌐
Python
docs.python.org › 3.5 › howto › curses.html
Curses Programming with Python — Python 3.5.10 documentation
from curses import wrapper def main(stdscr): # Clear screen stdscr.clear() # This raises ZeroDivisionError when i == 10.