def _cw_menu_display(cls):
x = 0
# Because cls with MENU will add 1 to y in _fix_xy, we need true origin
y = -1
# Makes the menu standout
menu_attrs = curses.A_REVERSE | curses.A_BOLD
saved_pos = cls.getxy()
for menu in Menu.ALL:
# double check we're not going to write out of bounds
if x + len(menu.title) + 2 >= cls.WIDTH:
raise CursedSizeError('Menu %s exceeds width of window: x=%d' %
(menu.title, x))
y = -1
cls.addstr(menu.title + ' ', x, y, attr=menu_attrs)
mxlen = max([len(str(i)) for i in menu.items])
if menu is cls._OPENED_MENU:
for item in menu.items:
y += 1
itemstr = str(item)
wspace = (mxlen - len(itemstr)) * ' '
itemstr = itemstr + wspace
if item is menu.selected:
attr = curses.A_UNDERLINE
else:
attr = curses.A_REVERSE
cls.addstr(itemstr, x, y, attr=attr)
# For the empty space filler
x += len(menu.title) + 2
# color the rest of the top of the window
extra = 2 if cls.BORDERED else 0
cls.addstr(' ' * (cls.WIDTH - x - extra), x, -1, attr=menu_attrs)
cls.move(*saved_pos)
评论列表
文章目录