Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When using curses.initscr() printing to screen doesn't work #87

Open
mobluse opened this issue Jun 3, 2024 · 1 comment
Open

When using curses.initscr() printing to screen doesn't work #87

mobluse opened this issue Jun 3, 2024 · 1 comment

Comments

@mobluse
Copy link

mobluse commented Jun 3, 2024

I wrote a small test program in snek version 1.9 in most updated Debian GNU/Linux 12 (bookworm) aarch64 installed using apt on Raspberry Pi 4 B and I use LXTerminal 0.4.0, but it doesn't output when I use curses.initscr(), but works when I don't use it. It moves the cursor, but erase() and addstr() doesn't affect the screen.

curses.initscr() # I also tried stdscr=curses.initscr()
stdscr.erase()
stdscr.addstr(5, 16, "Hello")
stdscr.move(9, 0)
stdscr.refresh()
curses.endwin()

This works:

#curses.initscr()
stdscr.erase()
stdscr.addstr(5, 16, "Hello")
stdscr.move(9, 0)
stdscr.refresh()
#curses.endwin()

I intended to write a small arcade game and then I probably need initscr() in order to read key presses without blocking, but now I'm stuck at not being able to output. Raspberry Pi with this OS and terminal emulator is a very common system.

@mobluse
Copy link
Author

mobluse commented Jun 3, 2024

I discovered my error: you have to use getch() or some other delay mechanism, because curses prints to another screen and then switches back.

This works with both python and snek:

import curses
stdscr=curses.initscr()
stdscr.erase()
stdscr.addstr(5, 16, "Hello")
stdscr.move(9, 0)
stdscr.refresh()
stdscr.getch()
curses.endwin()

A minimal version for snek:

curses.initscr()
stdscr.erase()
stdscr.addstr(5, 16, "Hello")
stdscr.move(9, 0)
stdscr.refresh()
stdscr.getch()
curses.endwin()

It might be useful to note this in the documentation. It's also useful that snek can use some stdscr methods without initscr().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant