Curses using changing data
Question: I have the following code. The number range increments by 1 each time. i.e 1-9
then 2-10 etc. I want to display this within a shell window using python via
curses.

The goal is to have a list of text that is constantly changing.

    
    
    from itertools import cycle
    import curses, contextlib, time
    
    @contextlib.contextmanager
    def curses_screen():
        """Contextmanager's version of curses.wrapper()."""
        try:
            stdscr=curses.initscr()
            curses.noecho()
            curses.cbreak()
            stdscr.keypad(1)
            try: curses.start_color()
            except: pass
    
            yield stdscr
        finally:
            stdscr.keypad(0)
            curses.echo()
            curses.nocbreak()
            curses.endwin()
    
    with curses_screen() as stdscr:
        pad = curses.newpad(100, 100)
        pad.addstr(0,0, curses.longname())
    
        coord = 5, 5, 10, 75
        # simulate changing text #
        for z in range(1,10):
            s,e = z+1,z+10
            for x in range(s,e):
                pad.addstr(x,0, str(x))
        pad.refresh(0, 0, *coord)
    

With this code nothing is printed to the screen ? Note : The reason Ive used a
newpad is so that I eventually scroll through this list.

Thanks,


Answer: It's not that nothing is printed to the screen, it's that you do all your
printing in a few microseconds, at which point you restore the pre-`curses`
screen and exit. Throw in a `pad.getch()` or just a `time.sleep(1)` and you'll
see the output.

If you want this to go slowly enough that you can watch it, instead of as fast
as your computer can count up numbers, you'll want a delay (and a `refresh`)
inside the loop.

