Videos
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.
» pip install Uni-Curses
I believe you are looking for curses.wrapper See http://docs.python.org/dev/library/curses.html#curses.wrapper
It will do curses.cbreak(), curses.noecho() and curses_screen.keypad(1) on init and reverse them on exit, even if the exit was an exception.
Your program goes as a function to the wrapper, example:
def main(screen):
"""screen is a curses screen passed from the wrapper"""
...
if __name__ == '__main__':
curses.wrapper(main)
You could do this:
def main():
curses.initscr()
try:
curses.cbreak()
for i in range(3):
time.sleep(1)
curses.flash()
pass
print( "Hello World" )
finally:
curses.endwin()
Or more nicely, make a context wrapper:
class CursesWindow(object):
def __enter__(self):
curses.initscr()
def __exit__(self):
curses.endwin()
def main():
with CursesWindow():
curses.cbreak()
for i in range(3):
time.sleep(1)
curses.flash()
pass
print( "Hello World" )