Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to scroll with curses?

How to scroll with curses? I tried the following, but it fails:

import curses

def main(stdscr):

    stdscr.clear()

    # Display 10 numbered lines:
    for line in range(10):
        stdscr.addstr(line, 0, str(line))

    stdscr.getch()  # Wait for a key press

    # Scrolling:
    stdscr.setscrreg(0, 9)  # Set scrolling region
    for _ in range(5):
        stdscr.scroll()  # Fails!
        stdscr.getch()

curses.wrapper(main)

The error does not give much information:

    stdscr.scroll()
_curses.error: scroll() returned ERR

I tried both with the Terminal application in OS X and in an xterm (OS X too), but the error is the same in both cases.

like image 544
Eric O Lebigot Avatar asked Oct 31 '22 09:10

Eric O Lebigot


1 Answers

Alright: using stdscr.scrollok(True) before scrolling works (I thought that I had tried it, but apparently that was in a different context).

It thus seems that scroll() did something to the cursor that moved it beyond the bottom of the window.

like image 56
Eric O Lebigot Avatar answered Nov 15 '22 05:11

Eric O Lebigot