gliss/rtm-ncurses — Issue #3: With enough lists, statusline crashes on request
Author: takeshitakenji
Created: 2012-01-30 17:35:02+00:00
State: open

I noticed that the test script crashes if you have enough lists:

```
% python rtm-test.py
Traceback (most recent call last):
File "rtm-test.py", line 62, in
curses.wrapper(main)
File "/usr/lib/python2.7/curses/wrapper.py", line 43, in wrapper
return func(stdscr, *args, **kwds)
File "rtm-test.py", line 42, in main
display.addView(l.name.lower())
File "/home/neil/Programs/rtm-ncurses/rtmcurses/display/display.py", line 161, in addView
self.statusline.fillFromViewlist(self.positions)
File "/home/neil/Programs/rtm-ncurses/rtmcurses/display/statusline.py", line 53, in fillFromViewlist
self.refresh()
File "/home/neil/Programs/rtm-ncurses/rtmcurses/display/statusline.py", line 36, in refresh
self.win.addstr(" [%d] %s" % (i, name))
_curses.error: addstr() returned ERR
```

It's a simple fix to just catch it, and it seems to work pretty well when I try it:

def refresh(self):
self.win.erase()

self.win.addstr("(%s)" % self.status)
for i, name in enumerate(self.viewlist):
try:
if name in self.colors:
self.win.addstr(" [%d] %s" % (i, name), self.colors[name])
else:
self.win.addstr(" [%d] %s" % (i, name))
except curses.error:
break

self.win.refresh()

I'm just wondering if that's ideal, though.