def yes_no(lightbar, msg, prompt_msg='are you sure? ', attr=None): """ Prompt user for yes/no, returns True for yes, False for no. """ term = getterminal() keyset = { 'yes': (u'y', u'Y'), 'no': (u'n', u'N'), } echo(u''.join(( lightbar.border(), lightbar.pos(lightbar.yloc + lightbar.height - 1, lightbar.xpadding), msg, u' ', prompt_msg, ))) sel = Selector(yloc=lightbar.yloc + lightbar.height - 1, xloc=term.width - 25, width=18, left='Yes', right=' No ') sel.colors['selected'] = term.reverse_red if attr is None else attr sel.keyset['left'].extend(keyset['yes']) sel.keyset['right'].extend(keyset['no']) echo(sel.refresh()) while True: inp = getch() echo(sel.process_keystroke(inp)) if ((sel.selected and sel.selection == sel.left) or inp in keyset['yes']): # selected 'yes', return True elif ((sel.selected or sel.quit) or inp in keyset['no']): # selected 'no' return False
def prompt_ok(): """ Prompt user to continue, True if they select yes. """ from x84.bbs import getsession, getterminal, echo, getch, Selector session, term = getsession(), getterminal() prompt_confirm = u'EVERYthiNG lOOk Ok ?' prompt_continue = u'YES (CONtiNUE)' prompt_chg = u'NO! (ChANGE)' def prompt_ok_dumb(): """ Dummy terminal prompt for confirm/cancel. """ echo('\r\n\r\n%s\r\n' % (prompt_confirm,)) echo('1 - %s\r\n' % (prompt_continue,)) echo('2 - %s\r\n\r\n' % (prompt_chg,)) echo('select (1, 2) --> ') while True: inp = getch() if inp == u'1': return True elif inp == u'2': return False if session.env.get('TERM') == 'unknown': return prompt_ok_dumb() sel = Selector(yloc=term.height - 1, xloc=5, width=term.width - 10, left=prompt_continue, right=prompt_chg) echo(term.normal) echo(term.move(term.height - 2, 0) + term.clear_eol) echo(prompt_confirm.center(term.width - 1) + '\r\n') echo(term.clear_eol + sel.refresh()) while True: echo(sel.process_keystroke(getch())) if sel.selected: return True if sel.selection == prompt_continue else False
def yes_no(lightbar, msg, prompt_msg='are you sure? ', attr=None): """ Prompt user for yes/no, returns True for yes, False for no. """ term = getterminal() keyset = { 'yes': (u'y', u'Y'), 'no': (u'n', u'N'), } echo(u''.join(( lightbar.border(), lightbar.pos(lightbar.yloc + lightbar.height - 1, lightbar.xpadding), msg, u' ', prompt_msg,))) sel = Selector(yloc=lightbar.yloc + lightbar.height - 1, xloc=term.width - 25, width=18, left='Yes', right=' No ') sel.colors['selected'] = term.reverse_red if attr is None else attr sel.keyset['left'].extend(keyset['yes']) sel.keyset['right'].extend(keyset['no']) echo(sel.refresh()) term = getterminal() while True: inp = term.inkey() echo(sel.process_keystroke(inp)) if((sel.selected and sel.selection == sel.left) or inp in keyset['yes']): # selected 'yes', return True elif((sel.selected or sel.quit) or inp in keyset['no']): # selected 'no' return False