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 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 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 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_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') 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
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_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