I've written a curses program in python. It runs fine. However, when I use nodelay()
, the program exits straight away after starting in the terminal, with nothing shown at all (just a new prompt).
EDIT
This code will reproduce the bug:
sc = curses.initscr() sc.nodelay(1) # But removing this line allows the program to run properly for angry in range(20): sc.addstr(angry, 1, "hi")
Here's my full code
import curses, time, sys, random def paint(x, y, i): #... def string(s, y): #... def feed(): #... sc = curses.initscr() curses.start_color() curses.curs_set(0) sc.nodelay(1) ######################################### # vars + colors inited for angry in range(20): try: dir = chr(sc.getch()) sc.clear() feed() #lots of ifs body.append([x, y]) body.pop(0) for point in body: paint(*point, i=2) sc.move(height-1, 1) sc.refresh() time.sleep(wait) except Exception as e: print sys.exc_info()[0], e sc.getch() curses.beep() curses.endwin()
Why is this happenning, and how can I use nodelay()
safely?