Esempio n. 1
0
def set_password(user):
    """
    Prompt for user.password, minimum length.
    """
    # pylint: disable=R0914
    #        Too many local variables
    from x84.bbs import getterminal, echo, ini, LineEditor
    term = getterminal()
    hidden_ch = u'x'
    prompt_password = u'password: '******'   again: '
    msg_empty = u'ENtER A PASSWORd!'
    msg_tooshort = u'TOO ShORt, MUSt bE At lEASt %s.'
    msg_unmatched = u'VERifY MUSt MAtCH!'
    width = ini.CFG.getint('nua', 'max_pass')
    min_pass = ini.CFG.getint('nua', 'min_pass')
    while True:
        echo(u'\r\n\r\n' + term.clear_eol + term.normal + prompt_password)
        led = LineEditor(width)
        led.hidden = hidden_ch
        password = led.read()
        if password == u'' or password is None:
            warning(msg_empty)
        elif len(password) < min_pass:
            warning(msg_tooshort % min_pass)
        else:
            echo(u'\r\n\r\n' + term.clear_eol + term.normal + prompt_verify)
            led = LineEditor(width)
            led.hidden = hidden_ch
            verify = led.read()
            if password != verify:
                warning(msg_unmatched)
                continue
            user.password = password
            return
Esempio n. 2
0
def add_question():
    term = getterminal()
    db = DBProxy(databasename)
    questions = []
    amount_of_alternatives = []
    index = {}
    alternatives = {}
    results = {}
    index = db['index']
    questions = db['questions']
    alternatives = db['alternatives']
    results = db['results']
    amount_of_alternatives = db['amount_of_alternatives']
    amount_of_questions = len(questions)

    echo(term.clear + term.white + u'\r\nQuestion: ')
    le = LineEditor(65)
    new_question = le.read()
    if new_question == '' or new_question == None:
        return

    echo(
        term.bold_black(u'\r\n\r\nLeave a blank line when you are finished..'))
    new_amount = 0
    while True:
        echo(term.normal + term.white + u'\r\nchoice ' + term.red +
             str(new_amount) + term.white + u': ')
        le = LineEditor(48)
        alternatives[(amount_of_questions, new_amount)] = le.read()
        if alternatives[(amount_of_questions,
                         new_amount)] == '' or alternatives[(
                             amount_of_questions, new_amount)] == None:
            break
        else:
            results[(amount_of_questions, new_amount)] = 0
            new_amount = new_amount + 1

    if new_amount > 0:
        echo(term.white(u'\r\n\r\nSave this voting question?'))
        answer = ynprompt()
        if answer == 1:
            questions.append(new_question)
            amount_of_alternatives.append(new_amount)

            indexcounter = db['indexcounter']
            indexcounter = indexcounter + 1
            index.append(str(indexcounter))

            db['indexcounter'] = indexcounter
            db['index'] = index
            db['questions'] = questions
            db['amount_of_alternatives'] = amount_of_alternatives
            db['results'] = results
            db['amount_of_questions'] = amount_of_questions
            db['alternatives'] = alternatives

            waitprompt(term)
Esempio n. 3
0
def do_login(term):
    sep_ok = getattr(term, color_secondary)(u'::')
    sep_bad = getattr(term, color_primary)(u'::')
    colors = {'highlight': getattr(term, color_primary)}
    for _ in range(login_max_attempts):

        term.goto_y(10)
        echo(u'\r\n\r\n{sep} Login: '******''

        if handle.strip() == u'':
            continue

        # user says goodbye
        if handle.lower() in bye_usernames:
            return

        # user applies for new account
        if new_allowed and handle.lower() in new_usernames:
            gosub(new_script)
            display_banner(term)
            continue

        # user wants to reset password
        if reset_allowed and handle.lower() == 'reset':
            gosub(reset_script)
            display_banner(term)
            continue

        # user wants to login anonymously
        if anonymous_allowed and handle.lower() in anonymous_names:
            user = User('anonymous')
        else:
            # authenticate password
            echo(u'\r\n\r\n{sep} Password: '******''

            user = authenticate_user(handle, password)
            if not user:
                echo(u'\r\n\r\n{sep} Login failed.'.format(sep=sep_bad))
                continue

        goto(top_script, handle=user.handle)

    echo(u'\r\n\r\n{sep} Too many authentication attempts.\r\n'.format(
        sep=sep_bad))
Esempio n. 4
0
def get_article(term, articles):
    """ Prompt for an article number, return matching article. """
    moveto_lastline = term.move(term.height, 0)
    width = term.width
    if term.kind.startswith('ansi'):
        # bah syncterm
        moveto_lastline = term.move(term.height - 1, 0)
        width -= 1
    echo(u''.join((
        moveto_lastline + getattr(term, COLOR_MAIN),
        term.center('', width),
        moveto_lastline,
    )))
    echo(u':: enter article #: ')
    article_idx = LineEditor(width=len(str(ARTICLE_LIMIT)),
                             colors={
                                 'highlight': getattr(term, COLOR_MAIN)
                             }).read()
    if article_idx is None:
        # pressed escape
        return None
    try:
        return articles[int(article_idx) - 1]
    except (ValueError, IndexError):
        # not an integer, or out of range
        return None
Esempio n. 5
0
def get_node(sessions):
    """ Prompt user for session node, Returns node & session attributes. """
    from x84.bbs import ini, LineEditor, echo
    max_user = ini.CFG.getint('nua', 'max_user')
    invalid = u'\r\ninvalid.'
    echo(u'\r\n\r\nNOdE: ')
    node = LineEditor(max_user).read()

    if node is None or 0 == len(node):
        # cancel
        return (None, None)

    try:
        node = int(node)
    except ValueError:
        # not an int
        echo(invalid)
        return (None, None)

    for tgt_node, (_, attrs) in get_nodes(sessions):
        if tgt_node == node:
            return (tgt_node, attrs)

    # not found
    echo(invalid)
    return (None, None)
Esempio n. 6
0
def saysomething(dumb=True):
    """
    Prompt user to post oneliner, also prompt user to post
    to bbs-scene.org if configured, returning background Thread.
    """
    import time
    from x84.bbs import getsession, getterminal, echo, LineEditor, ini
    session, term = getsession(), getterminal()
    prompt_say = u'SAY WhAt ?! '
    # heard_msg = u'YOUR MESSAGE hAS bEEN VOiCEd.'

    yloc = term.height - 3
    xloc = max(0, ((term.width / 2) - (MAX_INPUT / 2)))
    if dumb:
        echo(u'\r\n\r\n' + term.bold_blue(prompt_say))
    else:
        echo(term.move(yloc, xloc) or u'\r\n\r\n')
        echo(term.bold_blue(prompt_say))
    ole = LineEditor(MAX_INPUT)
    ole.highlight = term.green_reverse
    oneliner = ole.read()
    if oneliner is None or 0 == len(oneliner.strip()):
        if not dumb:
            # clear input line,
            echo(term.normal + term.move(yloc, 0) + term.clear_eol)
        return None

    session.user['lastliner'] = time.time()
    # post local-onlyw hen bbs-scene.org is not configured
    if not ini.CFG.has_section('bbs-scene'):
        add_oneline(oneliner.strip())
        return None
    return post_bbs_scene(oneliner, dumb)
Esempio n. 7
0
def try_pass(user):
    """
    Prompt for password and authenticate, returns True if succesfull.
    """
    # pylint: disable=R0914
    #         Too many local variables
    from x84.bbs import getsession, getterminal, ini, LineEditor, echo
    session, term = getsession(), getterminal()
    prompt_pass = u'pass: '******'\r\n\r\n  ' + term.yellow_reverse(u"Encrypting ..")
    badpass_msg = (u'\r\n\r\n' + term.red_reverse + u"'%s' login failed." +
                   term.normal)
    max_pass = int(ini.CFG.get('nua', 'max_pass'))
    # prompt for password, disable input tap during, mask input with 'x',
    # and authenticate against user record, performing a script change to
    # topscript if sucessful.
    # pylint: disable=W0212
    #         Access to a protected member _tap_input of a client class
    echo(term.move(term.height, max_pass + 10) + prompt_pass)
    chk = session._tap_input  # <-- save
    session._tap_input = False
    lne = LineEditor(max_pass)
    lne.hidden = u'x'
    password = lne.read()
    session._tap_input = chk  # restore -->
    if password is not None and 0 != len(password):
        echo(status_auth)
        if user.auth(password):
            return True
    denied(badpass_msg % (user.handle, ))
    return False
Esempio n. 8
0
def set_sacookies(user):
    """
    set SA cookies
    """
    from x84.bbs import getterminal, echo, ini, LineEditor
    term = getterminal()
    prompt_sausercookie = u'SA \'user\' cookie data: '
    echo(u'\r\n' + term.clear_eol + term.normal + prompt_sausercookie)
    user['sausercookie'] = LineEditor(50, u'').read()
    if user['sausercookie'] is None:
        user['sausercookie'] = u''
    prompt_sapasscookie = u'SA \'password\' cookie data: '
    echo(u'\r\n' + term.clear_eol + term.normal + prompt_sapasscookie)
    user['sapasscookie'] = LineEditor(50, u'').read()
    if user['sapasscookie'] is None:
        user['sapasscookie'] = u''
Esempio n. 9
0
File: weather.py Progetto: hick/x84
def chose_location_dummy(locations):
    """
    dummy pager to chose location
    """
    from x84.bbs import getterminal, echo, getch, LineEditor
    term = getterminal()
    msg_enteridx = (
        term.bold_yellow(u'('),
        term.underline_yellow(u'0'),
        term.yellow(u'-'),
        term.underline_yellow(u'%d' % (len(locations) - 1, )),
        term.yellow(u','),
        term.underline_yellow('Escape'),
        term.bold_white(u':'),
        term.yellow('exit'),
        term.bold_yellow(u')'),
        u' ',
        term.reverse_yellow(':'),
    )
    max_nwidth = len('%d' % (len(locations) - 1, ))

    def disp_entry(num, loc):
        """ Display City, State.  """
        return u''.join((
            term.bold_yellow(u'['),
            u'%*d' % (max_nwidth, num),
            term.bold_yellow(u']'),
            u' ',
            term.yellow(loc['city']),
            u', ',
            term.yellow(loc['state']),
            u'\r\n',
        ))

    echo(u'\r\n\r\n')
    lno = 3
    for num, loc in enumerate(locations):
        echo(disp_entry(num, loc))
        lno += 1
        if lno != 0 and (0 == lno % (term.height)):
            echo(term.yellow_reverse('--MORE--'))
            if getch() is None:
                break
            echo(u'\r\n')
            lno += 1
    idx = u''
    while True:
        echo(u'\r\n' + u''.join(msg_enteridx))
        idx = LineEditor(width=max_nwidth, content=idx).read()
        if idx is None or len(idx) == 0:
            return None
        try:
            int_idx = int(idx)
        except ValueError as err:
            echo(term.bold_red(u'\r\n%s' % (err, )))
            continue
        if int_idx < 0 or int_idx > len(locations) - 1:
            echo(term.bold_red(u'\r\nValue out of range'))
            continue
        return locations[int_idx]
Esempio n. 10
0
def do_select_encoding(term, session):
    editor_colors = {'highlight': term.black_on_green}
    dirty = True
    while True:
        if session.poll_event('refresh') or dirty:
            # attempt to coerce encoding of terminal to match session.
            coerce_terminal_encoding(term, session.encoding)

            # display artwork and prompt
            vertical_padding = 2 if term.height >= 24 else 0
            display_banner(filepattern=art_file,
                           encoding=art_encoding,
                           vertical_padding=vertical_padding)
            display_prompt(term)
            dirty = False

        inp = LineEditor(1, colors=editor_colors).read()

        if inp is None or inp.lower() == 'd':
            break
        elif len(inp):
            # bad input -- reposition cursor for next LineEditor()
            echo(u'\b')
        if inp.lower() == u'u' and session.encoding != 'utf8':
            # switch to utf8,
            session.encoding = 'utf8'
            dirty = True
        elif inp.lower() == 'c' and session.encoding != 'cp437':
            # or cp437
            session.encoding = 'cp437'
            dirty = True
Esempio n. 11
0
def prompt_input(term, key, sep_ok=u'::', width=None, colors=None):
    """ Prompt for and return input, up to given width and colorscheme. """
    colors = colors or {'highlight': term.yellow}
    sep_ok = colors['highlight'](sep_ok)

    echo(u'{sep} {key:<8}: '.format(sep=sep_ok, key=key))
    return LineEditor(colors=colors, width=width).read() or u''
Esempio n. 12
0
def add_leaf_msgnet():
    import cryptography.fernet
    server_tags = get_ini(section='msg', key='server_tags', split=True)
    if not server_tags:
        raise ValueError(MSG_NO_SERVER_TAGS)

    if len(server_tags) == 1:
        server_tag = server_tags[0]
    else:
        while True:
            echo('chose a server tag: ')
            idx = 0
            for idx, tag in server_tags:
                echo(u'\r\n{0}. {1}'.format(idx, tag))
            echo(u'\r\n: ')
            inp = LineEditor(width=len(str(idx)).read())
            if inp is None:
                return
            try:
                server_tag = server_tags[int(inp)]
                break
            except ValueError:
                pass

    with DBProxy('{0}keys'.format(server_tag)) as key_db:
        board_id = max(map(int, key_db.keys()) or [-1]) + 1
        client_key = cryptography.fernet.Fernet.generate_key()
        key_db[board_id] = client_key
    echo(u'\r\n')
    echo(u'-' * 40)
    view_leaf_msgnet(server_tag, board_id)
Esempio n. 13
0
def add_comment(key):
    """ Prompt user to add a comment about a bbs. """
    # pylint: disable=R0914
    #        Too many local variables.
    from x84.bbs import getsession, getterminal, echo, DBProxy, LineEditor
    from x84.bbs import getch
    session, term = getsession(), getterminal()
    prompt_comment = u'\r\n\r\nWhAt YOU GOt tO SAY? '
    prompt_chg = u'\r\n\r\nChANGE EXiStiNG ? [yn] '
    echo(term.move(term.height, 0))
    echo(prompt_comment)
    comment = LineEditor(max(10, term.width - len(prompt_comment) - 5)).read()
    if comment is None or 0 == len(comment.strip()):
        return
    new_entry = (session.handle, comment)
    comments = DBProxy('bbslist', 'comments')
    comments.acquire()
    existing = comments[key]
    if session.handle in (_nick for (_nick, _cmt) in comments[key]):
        # change existing comment,
        echo(prompt_chg)
        if getch() not in (u'y', u'Y'):
            comments.release()
            return
        # re-define list without existing entry, + new entry
        comments[key] = [(_enick, _ecmt) for (_enick, _ecmt) in existing
                         if session.handle != _enick] + [new_entry]
        comments.release()
        return
    # re-define as existing list + new entry
    comments[key] = existing + [new_entry]
    comments.release()
Esempio n. 14
0
def upload_files(term, protocol='xmodem1k'):
    """ Upload files. """
    echo(term.clear)
    while True:
        echo(u'Filename (empty to quit):\r\n')
        led = LineEditor(width=term.width - 1)
        led.refresh()
        inp = led.read()
        led = None
        if inp:
            for illegal in (os.path.sep, u'..', u'~',):
                if illegal in inp:
                    echo(term.bold_red(u'\r\nIllegal filename.\r\n'))
                    term.inkey()
                    return

            echo(term.bold(
                u'\r\nBegin your {0} sending program now.\r\n'
                .format(protocol)))

            upload_filename = os.path.join(UPLOADS_DIR, inp)
            try:
                upload = open(upload_filename, 'wb')
            except IOError as err:
                echo(term.bold_red('u\r\nIOError: {err}\r\n'.format(err=err)))
            else:
                if not recv_modem(upload, protocol):
                    echo(term.bold_red(u'Upload failed!\r\n'))
                    os.unlink(upload_filename)
                else:
                    echo(term.bold_green(u'Transfer succeeded.\r\n'))
            term.inkey()
        else:
            return
Esempio n. 15
0
def prompt_recipient(term, msg, colors, public=True):
    """ Prompt for recipient of message. """
    xpos = max(0, (term.width // 2) - (80 // 2))
    echo(term.move_x(xpos) + term.clear_eos)
    echo(u'Enter handle{0}.\r\n'.format(
        u', empty to address to all' if public else u''))
    echo(term.move_x(xpos) + ':: ')
    inp = LineEditor(username_max_length,
                     msg.recipient,
                     colors={
                         'highlight': colors['backlight']
                     }).read()

    if inp is None:
        echo(u''.join((term.move_x(xpos), colors['highlight']('Canceled.'),
                       term.clear_eol)))
        term.inkey(1)
        return False

    elif not inp.strip():
        # empty, recipient is None
        msg.recipient = None
        if public:
            return True
        return False

    inp = inp.strip()

    # validate/find user
    userlist = list_users()
    if inp in userlist:
        # exact match,
        msg.recipient = inp
        echo(u'\r\n')
        return True

    # nearest match
    for match in difflib.get_close_matches(inp.strip(), userlist):
        echo(u''.join(
            (term.move_x(xpos), u'{0} [yn]'.format(colors['highlight'](match)),
             term.clear_eol, u' ?\b\b')))
        while True:
            inp = term.inkey()
            if inp.code == term.KEY_ESCAPE:
                # escape/cancel
                return False
            elif inp.lower() == u'y':
                # accept match
                msg.recipient = match
                echo(u'\r\n')
                return True
            elif inp.lower() == u'n':
                # next match
                break

    echo(u''.join(
        (term.move_x(xpos), colors['highlight']('No match.'), term.clear_eol)))
    term.inkey(1)
    return False
Esempio n. 16
0
def get_line_editor(term, menu):
    """ Return a line editor suitable for menu entry prompts. """
    # if inp_key's were CJK characters, you should use term.length to measure
    # printable length of double-wide characters ... this is too costly to
    # enable by default.  Just a note for you east-asian folks.
    max_inp_length = max([len(item.inp_key) for item in menu])
    return LineEditor(width=max_inp_length,
                      colors={'highlight': getattr(term, color_backlight)})
Esempio n. 17
0
def prompt_input(term, key, **kwargs):
    """ Prompt for user input. """
    sep_ok = getattr(term, color_primary)(u'::')
    colors = {'highlight': getattr(term, color_primary)}
    echo(u'{sep} {key:>18}: '.format(sep=sep_ok, key=key))
    entry = LineEditor(colors=colors, **kwargs).read()
    if entry is None:
        log.debug('New User Account canceled at prompt key={0}.'.format(key))
    return entry
Esempio n. 18
0
def get_zipsearch(zipcode=u''):
    """
    Prompt user for zipcode or international city.
    """
    from x84.bbs import getterminal, LineEditor, echo
    term = getterminal()
    echo(u''.join((u'\r\n\r\n', term.bold_yellow(u'  -'),
                   term.reverse_yellow(u':'), u' ')))
    return LineEditor(width=min(30, term.width - 5), content=zipcode).read()
Esempio n. 19
0
def locate_user(term, point):
    """ Prompt for search pattern and return discovered User. """
    _color1, _color2, _color3 = [
        getattr(term, _color)
        for _color in (color_lowlight, color_highlight, color_field_edit)
    ]

    # show help
    width = term.width - (point.x * 2)
    help_txt = (u'Enter username or glob pattern.  Press escape to cancel.')
    y_offset = 0
    for y_offset, txt in enumerate(term.wrap(help_txt, width=width)):
        echo(term.move(point.y + y_offset, point.x))
        echo(_color1(txt) + term.clear_eol)
    point_prompt = Point(y=point.y + y_offset + 2, x=point.x)

    editor = LineEditor(nua.username_max_length, colors={'highlight': _color3})
    while True:
        # prompt for handle
        echo(term.move(*point_prompt))
        echo(u'handle: ' + term.clear_eol)
        inp = editor.read()

        point = Point(y=point_prompt.y + 2, x=point.x)
        if inp is None:
            # canceled (escape)
            return
        elif u'*' in inp or u'?' in inp:
            # a glob pattern, fetch all usernames
            handles = fnmatch.filter(list_users(), inp)
            if len(handles) == 0:
                echo(u''.join((term.move(*point),
                               u'No matches for {0}.'.format(_color2(inp)),
                               term.clear_eos)))
            elif len(handles) == 1:
                return get_user(handles[0])
            else:
                matches_text = (
                    u'{0} accounts matched, chose one: {1}.'.format(
                        _color2(str(len(handles))),
                        u', '.join(_color2(handle) for handle in handles)))
                echo(term.move(*point))
                for y_offset, txt in enumerate(
                        term.wrap(matches_text, width=width)):
                    echo(term.move(point.y + y_offset, point.x))
                    echo(txt + term.clear_eol)
                    if point.y + y_offset > term.height - 3:
                        # we simply cannot display anymore
                        break
                echo(term.clear_eos)
        else:
            handle = find_user(inp)
            if handle is not None:
                return get_user(handle)
            echo(u''.join(
                (term.move(*point),
                 u'No matches for {0}.'.format(_color2(inp)), term.clear_eos)))
Esempio n. 20
0
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
Esempio n. 21
0
def set_email(user):
    """
    Prompt for and set user.email, may be empty
    """
    from x84.bbs import getterminal, echo, ini, LineEditor
    term = getterminal()
    prompt_email = u'e-mail (optional): '
    width = ini.CFG.getint('nua', 'max_email')
    echo(u'\r\n\r\n' + term.clear_eol + term.normal + prompt_email)
    user.email = LineEditor(width, user.email).read()
    if user.email is None:
        user.email = u''
Esempio n. 22
0
def set_location(user):
    """
    Prompt for and set user.location, may be empty
    """
    from x84.bbs import getterminal, echo, ini, LineEditor
    term = getterminal()
    prompt_location = u'origin (optional): '
    width = ini.CFG.getint('nua', 'max_location')
    echo(u'\r\n\r\n' + term.clear_eol + term.normal + prompt_location)
    user.location = LineEditor(width, user.location).read()
    if user.location is None:
        user.location = u''
Esempio n. 23
0
def more(cont=False):
    """
    Returns True if user 'q'uit; otherwise False
    when prompting is complete (moar/next/whatever)
    """
    from x84.bbs import echo, getch, getterminal, LineEditor, DBProxy
    prompt_key = u'\r\n\r\nENtER BBS iD: '
    msg_badkey = u'\r\n\r\nbbS id iNVAliD!'
    term = getterminal()
    prompt = u', '.join(
        fancy_blue(char, blurb) for char, blurb in ((
            'i',
            'NfO',
        ), (
            'a',
            'dd',
        ), (
            'c',
            'OMMENt',
        ), (
            'r',
            'AtE',
        ), (
            't',
            'ElNEt',
        ), ('v', 'ANSi'), (
            'q',
            'Uit',
        )))
    if cont:
        prompt += u', ' + fancy_blue(' ', 'more')
    prompt += u': '
    while True:
        echo(u'\r\n')
        echo(u'\r\n'.join(
            term.wrap(text=prompt, width=(term.width - (term.width / 3)))))
        inp = getch()
        if inp in (u'q', 'Q'):
            return True
        elif inp is not None and type(inp) is not int:
            if cont and inp == u' ':
                echo(u'\r\n\r\n')
                return False
            if inp.lower() in u'acrtviACRTVI':
                # these keystrokes require a bbs key argument,
                # prompt the user for one
                echo(prompt_key)
                key = LineEditor(5).read()
                if (key is None or 0 == len(key.strip())
                        or not key in DBProxy('bbslist')):
                    echo(msg_badkey)
                    continue
                process_keystroke(inp, key)
Esempio n. 24
0
def prompt_tags(session, term, msg, colors, public=True):
    xpos = max(0, (term.width // 2) - (80 // 2))

    # conditionally enforce tag moderation
    moderated = get_ini('msg', 'moderated_tags', getter='getboolean')
    tag_moderators = set(get_ini('msg', 'tag_moderators', split=True))

    # enforce 'public' tag
    if public and 'public' not in msg.tags:
        msg.tags.add('public')
    elif not public and 'public' in msg.tags:
        msg.tags.remove('public')

    # describe all available tags, as we oft want to do.
    do_describe_available_tags(term, colors)

    # and remind ourselves of the available network tags,
    description = get_network_tag_description(term, colors)
    if description:
        show_description(term=term, color=None, description=description)

    echo(u''.join(
        (term.move_x(xpos), term.clear_eos,
         u'Enter tags, separated by commas.\r\n', term.move_x(xpos), u':: ')))

    all_tags = list_tags()

    while True:
        inp = LineEditor(subject_max_length,
                         u', '.join(sorted(msg.tags)),
                         colors={
                             'highlight': colors['backlight']
                         }).read()
        if inp is None:
            echo(u''.join(
                (term.move_x(xpos), colors['highlight']('Message canceled.'),
                 term.clear_eol)))
            term.inkey(1)
            return False

        msg.tags = set(filter(None, set(map(unicode.strip, inp.split(',')))))
        if moderated and not (tag_moderators | session.user.groups):
            cannot_tag = [_tag for _tag in msg.tags if _tag not in all_tags]
            if cannot_tag:
                echo(u''.join((u'\r\n', term.move_x(xpos), u', '.join(
                    (quote(tag, colors) for tag in cannot_tag)),
                               u': not allowed; this system is moderated.')))
                term.inkey(2)
                echo(term.move_up)
                map(msg.tags.remove, cannot_tag)
                continue

        return True
Esempio n. 25
0
def query_question():
    term = getterminal()
    session = getsession()
    db = DBProxy(databasename)
    questions = []
    index = []
    uservotingdata = []
    questions = db['questions']
    index = db['index']

    # create a new database file if none exists
    if not session.user.handle in db:
        db[session.user.handle] = {}
    uservotingdata = db[session.user.handle]

    echo(term.clear() + term.blue(u'>>') +
         term.white(u'questions availible\r\n') +
         term.blue(u'-' * 21 + '\r\n\r\n'))

    text = ''
    for i in range(0, len(questions)):
        if (index[i], 0) in uservotingdata:
            text = text + term.green(u'*')
        text = text + u''.join(term.magenta + u'(' + term.cyan + str(i) +
                               term.magenta + u') ' + term.white +
                               questions[i] + u'\r\n')
    text = text.splitlines()
    prompt_pager(content=text,
                 line_no=0,
                 colors={
                     'highlight': term.cyan,
                     'lowlight': term.green,
                 },
                 width=term.width,
                 breaker=None,
                 end_prompt=False)
    echo(term.move_x(0) + term.bold_black(u'* = already voted\r\n\r\n'))

    while True:
        echo(
            term.move_x(0) + term.magenta(
                u'select one of the questions above or press enter to return: '
            ))
        le = LineEditor(10)
        le.colors['highlight'] = term.cyan
        inp = le.read()
        if inp is not None and inp.isnumeric() and int(inp) < len(questions):
            return int(inp)
        else:
            # -1 in this case means that no valid option was chosen.. break
            # loop.
            return -1
Esempio n. 26
0
def prompt_subject(msg):
    """ Prompt for subject of message. """
    from x84.bbs import getterminal, LineEditor, echo, ini
    term = getterminal()
    max_subject = int(ini.CFG.getint('msg', 'max_subject'))
    lne = LineEditor(max_subject, msg.subject)
    lne.highlight = term.yellow_reverse
    echo(u'\r\n\r\n     SUBjECt: ')
    subject = lne.read()
    if subject is None or 0 == len(subject):
        return False
    msg.subject = subject
    return True
Esempio n. 27
0
def prompt_yesno(question):
    """ yes/no user prompt. """
    term = getterminal()
    sep = getattr(term, color_secondary)(u'**')
    colors = {'highlight': getattr(term, color_secondary)}
    echo(fixate_next(term, newlines=1))
    while True:
        echo(u'{sep} {question} [yn] ?\b\b'.format(sep=sep, question=question))
        yn = LineEditor(colors=colors, width=1).read() or u''
        if yn.lower() in (u'y', u'n'):
            return yn.lower() == u'y'
        echo(term.move_x(0) + term.clear_eol)
        echo(fixate_next(term, newlines=0))
Esempio n. 28
0
 def on_nicknameinuse(self, connection, event):
     """ Nick is being used; pick another one. """
     # pylint: disable=W0613
     self.session.buffer_event('irc-connected')
     self.connected = True
     echo(u''.join([self.term.normal, u'\r\n',
                    u'Your nickname is in use or illegal. Pick a new one '
                    u'(blank to quit):\r\n']))
     led = LineEditor(width=MAX_NICK)
     newnick = led.read()
     echo(u'\r\n')
     if not newnick:
         self.session.buffer_event('irc-quit', 'canceled')
         return
     connection.nick(newnick)
Esempio n. 29
0
def prompt_input(term, key, **kwargs):
    """ Prompt for user input. """
    sep_ok = getattr(term, color_secondary)(u'::')
    sep_bad = getattr(term, color_primary)(u'::')
    colors = {'highlight': getattr(term, color_primary)}

    echo(fixate_next(term))
    echo(u'{sep} {key:>18}: '.format(sep=sep_ok, key=key))
    entry = LineEditor(colors=colors, **kwargs).read() or u''
    if not entry.strip():
        echo(fixate_next(term))
        echo(u'{sep} Canceled !\r\n'.format(sep=sep_bad))
        log.debug('Password reset canceled at prompt key={0}.'.format(key))
        return u''

    return entry
Esempio n. 30
0
File: common.py Progetto: hick/x84
def prompt_input(term,
                 key,
                 content=u'',
                 sep_ok=u'::',
                 sep_bad=u'::',
                 width=None,
                 colors=None):
    """ Prompt for and return input, up to given width and colorscheme.
    """
    from x84.bbs import getterminal
    term = getterminal()
    colors = colors or {
        'highlight': term.yellow,
    }
    sep_ok = colors['highlight'](sep_ok)

    echo(u'{sep} {key:<8}: '.format(sep=sep_ok, key=key))
    return LineEditor(colors=colors, width=width).read() or u''