Skip to content

Instantly share code, notes, and snippets.

@bibiboot
Created August 6, 2012 07:01
Show Gist options
  • Save bibiboot/3271792 to your computer and use it in GitHub Desktop.
Save bibiboot/3271792 to your computer and use it in GitHub Desktop.
Hello world python curses
import curses
SCREEN_WIDTH, SCREEN_HEIGHT = 100, 100
class curses_screen:
def __enter__(self):
"""Initialize"""
self.stdscr = curses.initscr()
curses.cbreak()
curses.noecho()
self.stdscr.keypad(1)
# Initialize max width, height
SCREEN_HEIGHT, SCREEN_WIDTH = self.stdscr.getmaxyx()
return self.stdscr
def __exit__(self,a,b,c):
"""
Makes sure the exit does not
crashes the terminal
"""
curses.nocbreak()
self.stdscr.keypad(0)
curses.echo()
curses.endwin()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment