def prompt_body(msg): """ Prompt for 'body' of message, executing 'editor' script. """ from x84.bbs import echo, Selector, getterminal, getsession, gosub term = getterminal() session = getsession() inp = Selector(yloc=term.height - 1, xloc=term.width - 22, width=20, left=u'CONtiNUE', right=u'CANCEl') # check for previously existing draft if 0 != len(session.user.get('draft', u'')): # XXX display age of message inp = Selector(yloc=term.height - 1, xloc=term.width - 22, width=20, left=u'REStORE', right=u'ERASE') blurb = u'CONtiNUE PREViOUSlY SAVEd dRAft ?' echo(u'\r\n\r\n') echo(term.move(inp.yloc, inp.xloc - len(blurb))) echo(term.bold_yellow(blurb)) selection = inp.read() echo(term.move(inp.yloc, 0) + term.clear_eol) if selection == u'REStORE': msg.body = session.user['draft'] echo(u'\r\n\r\n') session.user['draft'] = msg.body if gosub('editor', 'draft'): echo(u'\r\n\r\n' + term.normal) msg.body = session.user.get('draft', u'') del session.user['draft'] return 0 != len(msg.body.strip()) return False
def prompt_network(msg, network_tags): """ Prompt for network message """ from x84.bbs import getterminal, echo, Lightbar, Selector from x84.bbs.ini import CFG term = getterminal() inp = Selector(yloc=term.height - 1, xloc=term.width - 22, width=20, left=u'YES', right=u'NO') blurb = u'iS thiS A NEtWORk MESSAGE?' echo(u'\r\n\r\n') echo(term.move(inp.yloc, inp.xloc - len(blurb))) echo(term.bold_yellow(blurb)) selection = inp.read() echo(term.move(inp.yloc, 0) + term.clear_eol) if selection == u'NO': return False lb = Lightbar(20, 20, term.height / 2 - 10, term.width / 2 - 10) lb.update([(tag, tag,) for tag in network_tags]) echo(u''.join(( term.clear , term.move(term.height / 2 - 11, term.width / 2 - 9) , term.bold_white(u'ChOOSE YOUR NEtWORk') ))) network = lb.read() if network is not None: msg.tags = (u'public', network,) return True return 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
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()) 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_recipient(msg): """ Prompt for recipient of message. """ # pylint: disable=R0914 # Too many local variables from x84.bbs import getterminal, LineEditor, echo, ini, list_users from x84.bbs import Selector import difflib term = getterminal() echo(u"ENtER %s, OR '%s' tO AddRESS All. %s to exit" % ( term.bold_yellow(u'hANdlE'), term.bold_yellow(u'None'), term.bold_yellow_underline('Escape'),)) echo(u'\r\n\r\n') max_user = ini.CFG.getint('nua', 'max_user') lne = LineEditor(max_user, msg.recipient or u'None') lne.highlight = term.yellow_reverse echo(term.clear_eol + u' RECiPiENt: ') recipient = lne.read() if recipient is None or lne.quit: return False userlist = list_users() if recipient in userlist: msg.recipient = recipient return True elif len(recipient) != 0 and recipient != 'None': for match in difflib.get_close_matches(recipient, userlist): blurb = u'did YOU MEAN: %s ?' % (match,) inp = Selector(yloc=term.height - 1, xloc=term.width - 22, width=20, left=u'YES', right=u'NO') echo(u''.join(( u'\r\n', term.move(inp.yloc, inp.xloc - len(blurb)), term.clear_eol, term.bold_yellow(blurb)))) selection = inp.read() echo(term.move(inp.yloc, 0) + term.clear_eol) if selection == u'YES': msg.recipient = match return True if selection is None or inp.quit: return False else: blurb = u' NO RECiPiENT; POSt tO PUbliC? ' inp = Selector(yloc=term.height - 1, xloc=term.width - 22, width=20, left=u'YES', right=u'NO') echo(u''.join(( u'\r\n', term.move(inp.yloc, inp.xloc - len(blurb)), term.clear_eol, term.bold_yellow(blurb)))) selection = inp.read() echo(term.move(inp.yloc, 0) + term.clear_eol) if selection == u'YES': msg.recipient = None return True
def get_ynbar(): """ Retrieve yes/no bar for quick login. """ from x84.bbs import getterminal, Selector term = getterminal() ynbar = Selector(yloc=term.height - 1, xloc=term.width - 31, width=30, left='Yes', right='No') ynbar.colors['selected'] = term.green_reverse ynbar.keyset['left'].extend((u'y', u'Y',)) ynbar.keyset['right'].extend((u'n', u'N',)) return ynbar
def get_selector(selection=u'No'): """ Return yes/no selector """ from x84.bbs import getterminal, Selector term = getterminal() selector = Selector( yloc=term.height - 1, xloc=(term.width / 2) - 25, width=50, left=u'Yes', right=u'No') selector.keyset['left'].extend((u'y', u'Y')) selector.keyset['right'].extend((u'y', u'Y')) selector.selection = selection selector.colors['selected'] = term.bold_white_reverse return selector
def prompt_recipient(msg, is_network_msg): """ Prompt for recipient of message. """ # pylint: disable=R0914 # Too many local variables from x84.bbs import getterminal, LineEditor, echo, ini, list_users from x84.bbs import Selector import difflib term = getterminal() style = getstyle() echo(u"ENtER %s, OR '%s' tO AddRESS All. %s to exit" % ( style['highlight'](u'hANdlE'), style['highlight'](u'None'), style['underline']('Escape'),)) echo(u'\r\n\r\n') max_user = ini.CFG.getint('nua', 'max_user') lne = LineEditor(max_user, msg.recipient or u'None') lne.highlight = term.yellow_reverse echo(term.clear_eol + u' RECiPiENt: ') recipient = lne.read() if recipient is None or lne.quit: return False if is_network_msg: return recipient userlist = list_users() if recipient in userlist: msg.recipient = recipient return True elif len(recipient) != 0 and recipient != 'None': for match in difflib.get_close_matches(recipient, userlist): blurb = u'did YOU MEAN: %s ?' % (match,) inp = Selector(yloc=term.height - 1, xloc=term.width - 22, width=20, left=u'YES', right=u'NO') echo(u''.join(( u'\r\n', term.move(inp.yloc, inp.xloc - len(blurb)), term.clear_eol, style['highlight'](blurb)))) selection = inp.read() echo(term.move(inp.yloc, 0) + term.clear_eol) if selection == u'YES': msg.recipient = match return True if selection is None or inp.quit: return False else: blurb = u' NO RECiPiENT; POSting tO PUbliC, PRESS ESC tO CANCEl' echo(u''.join((u'\r\n\r\n', term.clear_eol, style['highlight'](blurb)))) term.inkey(0.2) return True
def get_selector(selection): """ Instantiate a new selector, dynamicly for the window size. """ from x84.bbs import getterminal, Selector term = getterminal() width = max(30, (term.width / 2) - 10) xloc = max(0, (term.width / 2) - (width / 2)) sel = Selector(yloc=term.height - 1, xloc=xloc, width=width, left='utf8', right='cp437') sel.selection = selection return sel
def get_selector(selection=u'No'): """ Return yes/no selector """ from x84.bbs import getterminal, Selector term = getterminal() selector = Selector(yloc=term.height - 1, xloc=(term.width / 2) - 25, width=50, left=u'Yes', right=u'No') selector.keyset['left'].extend((u'y', u'Y')) selector.keyset['right'].extend((u'y', u'Y')) selector.selection = selection selector.colors['selected'] = term.bold_white_reverse return selector
def prompt_send(): """ Prompt for continue/cancel """ from x84.bbs import echo, Selector, getterminal term = getterminal() inp = Selector(yloc=term.height - 1, xloc=term.width - 22, width=20, left=u'CONtiNUE', right=u'CANCEl') blurb = u'CONtiNUE tO SENd MESSAGE' echo(term.move(inp.yloc, inp.xloc - len(blurb))) echo(term.bold_yellow(blurb)) selection = inp.read() echo(term.move(inp.yloc, 0) + term.clear_eol) if selection != u'CONtiNUE': return False return True
def prompt_abort(): """ Prompt for continue/abort """ from x84.bbs import echo, Selector, getterminal term = getterminal() inp = Selector(yloc=term.height - 1, xloc=term.width - 22, width=20, left=u'CONtiNUE', right=u'AbORt') blurb = u'CONtiNUE MESSAGE?' echo(u'\r\n\r\n') echo(term.move(inp.yloc, inp.xloc - len(blurb))) echo(term.bold_yellow(blurb)) selection = inp.read() echo(term.move(inp.yloc, 0) + term.clear_eol) if selection == u'AbORt': return True return False
def prompt_public(msg): """ Prompt for/enforce 'public' tag of message for unaddressed messages. """ from x84.bbs import getterminal, echo, Selector term = getterminal() if 'public' in msg.tags: # msg is addressed to None, and is tagged as 'public', return True # quit/escape if msg.recipient is None: # msg is addressed to nobody, force tag as 'public' or cancel, blurb = u"POStS AddRESSEd tO 'None' MUSt bE PUbliC!" inp = Selector(yloc=term.height - 1, xloc=term.width - 22, width=20, left=u'Ok', right=u'CANCEl') echo(term.move(inp.yloc, inp.xloc - len(blurb)) + term.clear_eol) echo(term.bold_red(blurb)) selection = inp.read() echo(term.move(inp.yloc, 0) + term.clear_eol) if selection == u'Ok': msg.tags.add(u'public') return True return False # quit/escape # not specified; you don't want this msg public? confirm, inp = Selector(yloc=term.height - 1, xloc=term.width - 24, width=20, left=u'YES!', right=u'NO') blurb = u'SENd PRiVAtE POSt?' echo(term.move(inp.yloc, inp.xloc - len(blurb))) echo(term.bold_yellow(blurb)) selection = inp.read() echo(term.move(inp.yloc, 0) + term.clear_eol) if selection == u'NO': msg.tags.add(u'public') return True elif selection == u'YES!': if u'public' in msg.tags: msg.tags.remove(u'public') return True return False # quit/escape
def prompt_body(msg): """ Prompt for 'body' of message, executing 'editor' script. """ from x84.bbs import echo, Selector, getterminal, getsession, gosub term = getterminal() session = getsession() inp = Selector(yloc=term.height - 1, xloc=term.width - 22, width=20, left=u'CONtiNUE', right=u'CANCEl') # check for previously existing draft if 0 != len(session.user.get('draft', u'')): # XXX display age of message inp = Selector(yloc=term.height - 1, xloc=term.width - 22, width=20, left=u'REStORE', right=u'ERASE') blurb = u'CONtiNUE PREViOUSlY SAVEd dRAft ?' echo(u'\r\n\r\n') echo(term.move(inp.yloc, inp.xloc - len(blurb))) echo(term.bold_yellow(blurb)) selection = inp.read() echo(term.move(inp.yloc, 0) + term.clear_eol) if selection == u'REStORE': msg.body = session.user['draft'] else: # delete the draft del session.user['draft'] echo(u'\r\n\r\n') content = gosub('editor', save_key=None, continue_draft=msg.body) if content and content.strip(): echo(u'\r\n\r\n' + term.normal) msg.body = content return True return False
def prompt_body(msg): """ Prompt for 'body' of message, executing 'editor' script. """ from x84.bbs import echo, Selector, getterminal, getsession, gosub term = getterminal() session = getsession() inp = Selector(yloc=term.height - 1, xloc=term.width - 22, width=20, left=u'CONtiNUE', right=u'CANCEl') blurb = u'CONtiNUE tO Edit MESSAGE bOdY' echo(u'\r\n\r\n') echo(term.move(inp.yloc, inp.xloc - len(blurb))) echo(term.bold_yellow(blurb)) selection = inp.read() echo(term.move(inp.yloc, 0) + term.clear_eol) if selection != u'CONtiNUE': return False if 0 != len(session.user.get('draft', u'')): inp = Selector(yloc=term.height - 1, xloc=term.width - 22, width=20, left=u'REStORE', right=u'ERASE') blurb = u'CONtiNUE PREViOUSlY SAVEd dRAft ?' echo(u'\r\n\r\n') echo(term.move(inp.yloc, inp.xloc - len(blurb))) echo(term.bold_yellow(blurb)) selection = inp.read() echo(term.move(inp.yloc, 0) + term.clear_eol) if selection == u'REStORE': msg.body = session.user['draft'] echo(u'\r\n\r\n') session.user['draft'] = msg.body if gosub('editor', 'draft'): echo(u'\r\n\r\n' + term.normal) msg.body = session.user.get('draft', u'') del session.user['draft'] return 0 != len(msg.body.strip()) return False