1
r = 0
mypad.addstr(0, 0, "Test...")

while 1:
    mypad.refresh(r, 0, 1, 1, 10, 10)
    c = mypad.getch()

    if c == curses.KEY_UP:
        r -= 1
    elif c == curses.KEY_DOWN:
        r += 1
    elif c == ord('q'): break 

Test... is displayed, but when I press up/down it just disappear.

Update:

actually when adding more lines I found it scrolls, but only upwards, not below initial position. No matter how big r will be, the text will stay on first row. What am I missing?

Pablo
  • 24,270
  • 32
  • 112
  • 196

1 Answers1

2

Check what values do you get for up/down arrows and compare them with curses.KEY_UP/DOWN. See My cursor keys do not work.

For example, key-up returns as 3 characters on my terminal:

import curses

with curses_screen() as stdscr:
    pad = curses.newpad(100, 100)
    pad.addstr(0,0, curses.longname())
    for i in range(1, 10):
        pad.addstr(i,0, str(i))

    coord = 5, 5, 20, 75
    pad.refresh(0, 0, *coord)

    KEY_UP, KEY_DOWN = 'AB'
    y = 0
    for c in iter(pad.getkey, 'q'):
        if c in '\x1b\x5b': continue # skip escape seq
        y -= (c == KEY_UP)
        y += (c == KEY_DOWN)
        y = min(max(y, 0), 9)
        pad.refresh(y, 0, *coord)

Definition of curses_screen().

Community
  • 1
  • 1
jfs
  • 346,887
  • 152
  • 868
  • 1,518