menu.py 文件源码

python
阅读 22 收藏 0 点赞 0 评论 0

项目:ssh-gateway 作者: bubbl 项目源码 文件源码
def runmenu(menu, parent):
  if parent is None:
    lastoption = "Exit"
  else:
    lastoption = "Return to %s menu" % parent['title']

  optioncount = len(menu['options'])
  pos=0
  oldpos=None
  x = None

  while x != ord('\n'):
    if pos != oldpos:
      oldpos = pos
      screen.border(1,1,1,1)
      screen.addstr(2,2, menu['title'], curses.A_STANDOUT)
      screen.addstr(4,2, menu['subtitle'], curses.A_BOLD)

      for index in range(optioncount):
        textstyle = n
        if pos == index:
          textstyle = h
        screen.addstr(7+index,4, "%d - %s" % (index+1, menu['options'][index]['title']), textstyle)
      textstyle = n
      if pos == optioncount:
        textstyle = h
      screen.addstr(7+optioncount,4, "%d - %s" % (optioncount+1, lastoption), textstyle)
      screen.refresh()

    x = screen.getch()

    if x >= ord('1') and x <= ord(str(optioncount+1)):
      pos = x - ord('0') - 1
    elif x == 258:
      if pos < optioncount:
        pos += 1
      else: pos = 0
    elif x == 259:
      if pos > 0:
        pos += -1
      else: pos = optioncount

  return pos
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号