The code below lets you walk around a small grid on the screen using the arrow keys putting "." where you've explored or been next to. Even though I have my refresh before the first getch (to get a key-stroke) the screen doesn't first display anything until you've moved off your starting position. Shouldn't the addstr followed by refresh immediately show and then the getch waits after that? I even tried adding a stdscr.refresh(), but that didn't help either. How do I get the screen to refresh immediately before waiting for the first key-stroke?
import curses
def start(stdscr):
curses.curs_set(0)
movement = curses.newpad(10, 10)
cur_x, cur_y = 5, 5
while True:
movement.addstr(cur_y, cur_x, '@')
for (x_off, y_off) in [(-1,0),(1,0),(0,-1),(0,1)]:
movement.addstr(cur_y + y_off, cur_x + x_off, '.')
movement.refresh(1, 1, 0, 0, 7, 7) #Nothing is displayed until after the first key-stroke
key_stroke = stdscr.getch()
move_attempt = False
if 0 < key_stroke < 256:
key_stroke = chr(key_stroke)
elif key_stroke == curses.KEY_UP and cur_y > 1:
cur_y -= 1
elif key_stroke == curses.KEY_DOWN and cur_y < 8:
cur_y += 1
elif key_stroke == curses.KEY_LEFT and cur_x > 1:
cur_x -= 1
elif key_stroke == curses.KEY_RIGHT and cur_x < 8:
cur_x += 1
else:
pass
if __name__ == '__main__':
curses.wrapper(start)