I am not so into ncurses, but it should be working on C, I do not know what is wrong, I just want to print some character to screen continuosly but I cannot find how to fix this error:
File "capture.py", line 37, in <module>
stdscr.move(y,x)
_curses.error: wmove() returned ERR
Code:
(irrelevant parts of the code are removed)
import curses
stdscr = curses.initscr()
curses.noecho();
palette = [' ', ' ', '.', '.', '/', 'c', '(', '@', '#', '8']
# index is something between 0 and len(palette), not important
for x in xrange(50):
for y in xrange(30):
stdscr.move(y,x)
sdtscr.addch(palette[index])
stdscr.refresh()
If you read the documentation for curses move (e.g., http://linux.die.net/man/3/move):
The first doesn’t seem likely to come up in Python, so the second is probably your problem. And a quick test shows that running your code works fine on a terminal that’s 30 rows or taller, but fails on a typical 24- or 25-row terminal.
If you want to make it easier to debug, first wrap the whole thing in a
try/finally:curses.endscr()(so your terminal isn’t left in a mess, possibly making it impossible to see the output). Then wrap the call tostdscr.movein atry/except:that logs x and y so you know where it fails. I’d also make the “30” into a command-line argument for quicker testing. Here’s a version with all those changes:Now
python cursetest 30prints:So, as I suspected, it’s failing at x=0, y=25.
And if I stretch my terminal out to 80×50, it works, but now
python cursetest 60fails:For that matter, if I shrink my terminal to 40×50,
python cursetest 30fails at the horizontal edge rather than the vertical:If you want to check for this in advance rather than trying to catch the error when it happens, try calling
getmaxyx()on the window; if y<30 you can display a nice error message and quit (or do something different, or whatever).Finally, a quick check shows that this doesn’t work in C either. Of course there’s no exception thrown, and you can ignore the error that’s returned if you want, but you just end up writing to position (24, 49) 300 times in a row. (And you could do the same thing in Python by doing a try/catch/pass around the move, if you really wanted…)