Пример #1
0
def display_banner(term):
    """ Display on-connect banner and set a few sequences. """

    # reset existing SGR attributes
    echo(term.normal)

    # set syncterm font, if any
    if syncterm_font and term.kind.startswith('ansi'):
        echo(syncterm_setfont(syncterm_font))

    # http://www.termsys.demon.co.uk/vtansi.htm
    # disable line-wrapping (SyncTerm does not honor, careful!)
    echo(u'\x1b[7l')

    if term.kind.startswith('xterm'):
        # http://www.xfree86.org/4.5.0/ctlseqs.html
        # Save xterm icon and window title on stack.
        echo(u'\x1b[22;0t')

    # move to beginning of line and clear, in case syncterm_setfont
    # has been mis-interpreted, as it follows CSI with space, which
    # causes most terminal emulators to receive literally after CSI.
    echo(term.move_x(0) + term.clear_eol)

    # display name of bbs and url to sourcecode.
    highlight = getattr(term, color_primary)
    sep = getattr(term, color_secondary)(u'::')

    echo(term.clear)  # clear the screen...

    # display on-connect banner (`art_file`)
    map(echo, showart(art_file, encoding=art_encoding, center=True))

    map(echo, showart("./art/login.ans", encoding=art_encoding, center=True))

    # display various ini-configured login username aliases.
    if new_allowed:

        echo(
            term.center(u"\r\nLogin as '{0}' to create an account.".format(
                highlight(new_usernames[0]))))
    if anonymous_allowed:
        echo(u"\r\nLogin as '{0}' is allowed.".format(
            highlight(anonymous_names[0])))
    if reset_allowed:
        echo(
            term.center(u"\r\nForgot password? Login as '{0}'.".format(
                highlight('reset'))))
Пример #2
0
def display_banner(filepattern, vertical_padding=0, **kwargs):
    """
    Start new screen and show artwork, centered.

    :param str filepattern: file to display
    :param int vertical_padding: number of blank lines to prefix art
    :return: number of lines displayed
    :rtype: int

    Remaining parameters are inherited from :func:`showart`, such
    as ``center`` and ``encoding``.  By default, ``center`` is True.
    """
    # This is unfortunate, we should use 'term' as first argument
    term = getterminal()
    kwargs['center'] = kwargs.get('center', True)

    # move to bottom of screen, reset attribute
    echo(term.move(term.height, 0) + term.normal)

    # create a new, empty screen
    echo(u'\r\n' * (term.height + 1))

    # move to home, insert vertical padding
    echo(term.home + (u'\r\n' * vertical_padding))

    art_generator = showart(filepattern, **kwargs)
    line_no = 0
    for line_no, txt in enumerate(art_generator):
        echo(txt)

    # return line number
    return line_no + vertical_padding
Пример #3
0
Файл: common.py Проект: hick/x84
def display_banner(filepattern, encoding=None, vertical_padding=0):
    """ Start new screen and show artwork, centered.

    :param filepattern: file to display
    :type filepattern: str
    :param encoding: encoding of art file(s).
    :type encoding: str or None
    :param vertical_padding: number of blank lines to prefix art
    :type vertical_padding: int
    :returns: number of lines displayed
    :rtype: int
    """
    term = getterminal()

    # move to bottom of screen, reset attribute
    echo(term.pos(term.height) + term.normal)

    # create a new, empty screen
    echo(u'\r\n' * (term.height + 1))

    # move to home, insert vertical padding
    echo(term.home + (u'\r\n' * vertical_padding))

    # show art
    art_generator = showart(filepattern, encoding=encoding,
                            auto_mode=False, center=True)
    line_no = 0
    for line_no, txt in enumerate(art_generator):
        echo(txt)

    # return line number
    return line_no + vertical_padding
Пример #4
0
def banner():
    term = getterminal()
    banner = ''
    artfile = os.path.join(os.path.dirname(__file__), 'art', 'bulletins.ans')
    for line in showart(artfile, 'topaz'):
        banner = banner + line
    return banner
Пример #5
0
def banner():
    term = getterminal()
    banner = ''
    artfile = os.path.join(os.path.dirname(__file__), 'art', 'bulletins.ans')
    for line in showart(artfile,'topaz'):
        banner = banner + line
    return banner
Пример #6
0
def displayfile(filename):
    term = getterminal()
    echo(term.clear + term.move(0, 0) + term.normal)

    text = {}
    counter = 0
    offset = 0
    keypressed = ''

    # the string array named text will be zerobased
    for line in showart(filename):
        text[counter] = line
        counter = counter + 1

    while True:
        echo(term.move(0, 0) + term.normal)
        # -2 om man vill spara en rad i botten
        for i in range(0, term.height - 1):
            if len(text) > i + offset:
                echo(term.clear_eol + u'\r' + text[i + offset])

        keypressed = getch()
        echo(term.hide_cursor)
        if keypressed == 'q' or keypressed == 'Q' or keypressed == term.KEY_ESCAPE or keypressed == term.KEY_ENTER:
            break

        if keypressed == term.KEY_HOME:
            offset = 0

        if keypressed == term.KEY_END:
            # if the textline has fewer lines than the screen..
            if len(text) < term.height:
                offset = 0
            else:
                offset = len(text) - term.height + 1

        if keypressed == term.KEY_DOWN:
            # offset < len(text) + term.height:
            if len(text) > offset + term.height - 1:
                offset = offset + 1

        if keypressed == term.KEY_UP:
            if offset > 0:
                offset = offset - 1

        if keypressed == term.KEY_LEFT or keypressed == term.KEY_PGUP:
            if offset > term.height:
                offset = offset - term.height + 2
            else:
                offset = 0

        if keypressed == term.KEY_RIGHT or keypressed == term.KEY_PGDOWN:
            if (offset + term.height * 2) - 1 < len(text):
                offset = offset + term.height - 2
            else:
                # if the textline has fewer lines than the screen..
                if len(text) < term.height:
                    offset = 0
                else:
                    offset = len(text) - term.height + 1
Пример #7
0
Файл: common.py Проект: hick/x84
def display_banner(filepattern, encoding=None, vertical_padding=0):
    """ Start new screen and show artwork, centered.

    :param filepattern: file to display
    :type filepattern: str
    :param encoding: encoding of art file(s).
    :type encoding: str or None
    :param vertical_padding: number of blank lines to prefix art
    :type vertical_padding: int
    :returns: number of lines displayed
    :rtype: int
    """
    term = getterminal()

    # move to bottom of screen, reset attribute
    echo(term.pos(term.height) + term.normal)

    # create a new, empty screen
    echo(u'\r\n' * (term.height + 1))

    # move to home, insert vertical padding
    echo(term.home + (u'\r\n' * vertical_padding))

    # show art
    art_generator = showart(filepattern,
                            encoding=encoding,
                            auto_mode=False,
                            center=True)
    line_no = 0
    for line_no, txt in enumerate(art_generator):
        echo(txt)

    # return line number
    return line_no + vertical_padding
Пример #8
0
def display_banner(filepattern, vertical_padding=0, **kwargs):
    """
    Start new screen and show artwork, centered.

    :param str filepattern: file to display
    :param int vertical_padding: number of blank lines to prefix art
    :return: number of lines displayed
    :rtype: int

    Remaining parameters are inherited from :func:`showart`, such
    as ``center`` and ``encoding``.  By default, ``center`` is True.
    """
    # This is unfortunate, we should use 'term' as first argument
    term = getterminal()
    kwargs['center'] = kwargs.get('center', True)

    # move to bottom of screen, reset attribute
    echo(term.move(term.height, 0) + term.normal)

    # create a new, empty screen
    echo(u'\r\n' * (term.height + 1))

    # move to home, insert vertical padding
    echo(term.home + (u'\r\n' * vertical_padding))

    art_generator = showart(filepattern, **kwargs)
    line_no = 0
    for txt in art_generator:
        line_no += 1
        echo(txt)

    # return line number
    return line_no + vertical_padding
Пример #9
0
Файл: editor.py Проект: hick/x84
def show_help(term, center=True):
    """
    Returns help text.
    """
    # clear screen
    echo(term.normal + ('\r\n' * (term.height + 1)) + term.home)

    map(echo, showart(os.path.join(here, 'art', 'po-help.ans')))
Пример #10
0
def show_help(term, center=True):
    """
    Returns help text.
    """
    # clear screen
    echo(term.normal + ('\r\n' * (term.height + 1)) + term.home)

    map(echo, showart(os.path.join(here, 'art', 'po-help.ans')))
Пример #11
0
Файл: vote.py Проект: hick/x84
def main():
    session = getsession()
    session.activity = u'hanging out in voting script'
    term = getterminal()
    echo(term.clear())

    db = DBProxy(databasename)  
    if not 'questions' in db:
        generate_database()

    while True: 
        echo(term.clear()) # clears the screen and displays the vote art header
        for line in showart(os.path.join(os.path.dirname(__file__),'art','vote.ans'),'topaz'):
            echo(term.cyan+term.move_x((term.width/2)-40)+line)

        if 'sysop' in session.user.groups:
            spacing = 1
        else:
            spacing = 7
            echo(' ')
        echo(term.magenta+'\n ('+term.cyan+'r'+term.magenta+')'+term.white+'esults'+' '*spacing)
        echo(term.magenta+'('+term.cyan+'v'+term.magenta+')'+term.white+'ote on a question'+' '*spacing)
        echo(term.magenta+'('+term.cyan+'a'+term.magenta+')'+term.white+'dd a new question'+' '*spacing)
        if 'sysop' in session.user.groups:
            echo(term.magenta+'('+term.cyan+'d'+term.magenta+')'+term.white+'elete a question'+' '*spacing)
        echo(term.magenta+'('+term.cyan+'q'+term.magenta+')'+term.white+'uit')
        echo(term.magenta+'\r\n\r\n\r\nx/84 voting booth command: ')  
        le = LineEditor(30)
        le.colors['highlight'] = term.cyan
        inp = le.read()
        inp = inp.lower() # makes the input indifferent to wheter you used lower case when typing in a command or not..

        if 'sysop' in session.user.groups and inp == 'd':
            while 1:
                questionnumber = query_question()
                if questionnumber == 999:
                    break
                delete_question(questionnumber)
        elif inp == 'r':
            while 1:
                questionnumber = query_question()
                if questionnumber == 999:
                    break
                list_results(questionnumber)
        elif inp == 'v':
            while 1:
                questionnumber = query_question()
                if questionnumber == 999:
                    break
                vote(questionnumber)
        elif inp == 'a':
            add_question()
        elif inp == 'q':
            return
        else:
            echo(term.red+'\r\nNo such command. Try again.\r\n') # if no valid key is pressed then do some ami/x esthetics.
            waitprompt()
Пример #12
0
Файл: logoff.py Проект: hick/x84
 def refresh_all(idx=None):
     """
     refresh screen, database, and return database index
     """
     echo(u''.join((u'\r\n\r\n', term.clear_eol,)))
     for line in showart(os.path.join(os.path.dirname(__file__), 'art','logoff.ans'),'topaz'):
         echo(line)
     idx = refresh_automsg(-1 if idx is None else idx)
     refresh_prompt(prompt_msg)
     return idx
Пример #13
0
def show_banner():
    """ Display main menu banner """
    from x84.bbs import showart, echo, getterminal
    import os

    artfile = os.path.join(os.path.dirname(__file__), 'art', 'main.ans')

    # displays a centered main menu header in topaz encoding for utf8
    for line in showart(artfile, 'topaz', center=True):
        echo(line)
Пример #14
0
def banner():
    """ Returns string suitable for displaying banner """
    from x84.bbs import getterminal, showart
    import os
    term = getterminal()
    banner = '\r\n'
    for line in showart(
            os.path.join(os.path.dirname(__file__), 'art', 'online.ans'), 'cp437'):
        banner = banner + term.move_x(max(0, (term.width / 2) - 40)) + line
    return (banner)
Пример #15
0
def show_banner():
    """ Display main menu banner """
    from x84.bbs import showart, echo, getterminal
    import os

    artfile = os.path.join(os.path.dirname(__file__), 'art', 'main.ans')

    # displays a centered main menu header in topaz encoding for utf8
    for line in showart(artfile, 'topaz', center=True):
        echo(line)
Пример #16
0
def heading():
    """ Return string suitable for display heading. """
    from x84.bbs import getterminal, showart
    import os

    term = getterminal()
    bar = ""
    for line in showart(os.path.join(os.path.dirname(__file__), "art", "onlinebar.ans"), "topaz"):
        bar = bar + term.move_x(max(0, (term.width / 2) - 40)) + line
    return u"\r\n".join((u"\r\n".join([term.center(pline, (term.width)) for pline in prompt()]), u"\r\n", bar))
Пример #17
0
def banner():
    """ Returns string suitable for displaying banner """
    from x84.bbs import getterminal, showart
    import os

    term = getterminal()
    banner = "\r\n"
    for line in showart(os.path.join(os.path.dirname(__file__), "art", "online.ans"), "cp437"):
        banner = banner + term.move_x(max(0, (term.width / 2) - 40)) + line
    return banner
Пример #18
0
def banner():
    """ Returns string suitable for displaying banner """
    from x84.bbs import getterminal, showart
    import os
    term = getterminal()
    banner = '\r\n'
    for line in showart(
            os.path.join(os.path.dirname(__file__), 'art', 'online.ans'), 'cp437'):
        banner = banner + term.move_x(max(0, (term.width / 2) - 40)) + line
    return (banner)
Пример #19
0
def heading():
    """ Return string suitable for display heading. """
    from x84.bbs import getterminal, showart
    import os
    term = getterminal()
    bar = ''
    for line in showart(
            os.path.join(os.path.dirname(__file__), 'art', 'onlinebar.ans'),
            'topaz'):
        bar = bar + term.move_x(max(0, (term.width / 2) - 40)) + line
    return u'\r\n'.join(
        (u'\r\n'.join([term.center(pline, (term.width))
                       for pline in prompt()]), u'\r\n', bar))
Пример #20
0
def heading():
    """ Return string suitable for display heading. """
    from x84.bbs import getterminal, showart
    import os
    term = getterminal()
    bar = ''
    for line in showart(
            os.path.join(os.path.dirname(__file__), 'art', 'onlinebar.ans'), 'topaz'):
        bar = bar + term.move_x(max(0, (term.width / 2) - 40)) + line
    return u'\r\n'.join((
        u'\r\n'.join([term.center(pline, (term.width))
                      for pline in prompt()]),
        u'\r\n', bar))
Пример #21
0
def display_banner(term):
    """ Display on-connect banner and set a few sequences. """

    # reset existing SGR attributes
    echo(term.normal)

    # set syncterm font, if any
    if syncterm_font and term.kind.startswith('ansi'):
        echo(syncterm_setfont(syncterm_font))

    # http://www.termsys.demon.co.uk/vtansi.htm
    # disable line-wrapping (SyncTerm does not honor, careful!)
    echo(u'\x1b[7l')

    if term.kind.startswith('xterm'):
        # http://www.xfree86.org/4.5.0/ctlseqs.html
        # Save xterm icon and window title on stack.
        echo(u'\x1b[22;0t')

    # move to beginning of line and clear, in case syncterm_setfont
    # has been mis-interpreted, as it follows CSI with space, which
    # causes most terminal emulators to receive literally after CSI.
    echo(term.move_x(0) + term.clear_eol)

    # display name of bbs and url to sourcecode.
    highlight = getattr(term, color_primary)
    sep = getattr(term, color_secondary)(u'::')

    echo(u'{sep} Connected to {name}.\r\n'.format(
        sep=sep, name=highlight(system_bbsname)))
    echo(u'{sep} See {url} for source code.\r\n'.format(
        sep=sep, url=highlight(__url__)))

    # display on-connect banner (`art_file`)
    map(echo, showart(art_file, encoding=art_encoding, center=True))

    # display various ini-configured login username aliases.
    if new_allowed:
        echo(u"   Login as '{0}' to create an account."
             .format(highlight(new_usernames[0])))
    if anonymous_allowed:
        echo(u"\r\n   Login as '{0}' is allowed."
             .format(highlight(anonymous_names[0])))
    if reset_allowed:
        echo(u"\r\n   Forgot password? Login as '{0}'."
             .format(highlight('reset')))
Пример #22
0
Файл: ol.py Проект: hick/x84
def banner():
    """ Return centered banner """
    from x84.bbs import getterminal, showart
    import os
    term = getterminal()
    output = u''
    output += u'\r\n\r\n' + term.normal
    if term.width >= 78:
        artfile = os.path.join(os.path.dirname(__file__), 'art', 'oneliner.ans')
        artfilewidth = 80
    if term.width >= 100:
        artfile = os.path.join(os.path.dirname(__file__), 'art', 'oneliner100.ans')
        artfilewidth = 100

    output += term.home + term.normal + term.clear
    for line in showart(artfile,'topaz'):
        output = output + term.move_x((term.width/2)-artfilewidth/2)+line
    return output + term.normal
Пример #23
0
def refresh_screen(term, who):
    # create a new, empty screen
    echo(term.normal)
    echo(term.move(term.height - 1, 0))
    echo(u'\r\n' * (term.height + 1))

    ans_height, ans_width = 24, 80
    if term.width < ans_width or term.height < ans_height:
        # screen is too small for ansi file, use ytalk-like format
        center_line = term.height // 2
        echo(term.move(center_line, 0))
        echo(term.center(u'= {0}@{1} ='.format(who, system_bbsname),
                         term.width, '-'))
        top_window = WindowDimension(
            yloc=-1, xloc=-1,
            height=center_line + 2,
            width=term.width + 2)
        bot_window = WindowDimension(
            yloc=center_line,
            xloc=-1,
            height=term.height - (center_line - 1),
            width=term.width + 2)
    else:
        # center ansi file
        center_y = (math.floor(term.height / 2 - (ans_height / 2)))
        center_x = math.floor(term.width / 2 - (ans_width / 2))
        ypos, xpos = max(0, int(center_y)), max(0, int(center_x))
        art_generator = showart(art_file, encoding=art_encoding)
        for y_offset, line in enumerate(art_generator):
            _ypos = ypos + y_offset
            if _ypos <= term.height:
                echo(term.move(_ypos, xpos))
                echo(line.rstrip())
        top_window = WindowDimension(
            yloc=ypos,
            xloc=xpos + 1,
            height=9, width=78)
        bot_window = WindowDimension(
            yloc=ypos + 14,
            xloc=xpos + 1,
            height=10, width=78)
    return top_window, bot_window
Пример #24
0
def main():
    """ Main procedure. """
    # pylint: disable=R0914,R0912
    #         Too many local variables
    #         Too many branches
    from x84.bbs import DBProxy, getsession, getterminal, echo
    from x84.bbs import ini, LineEditor, timeago, showart
    from x84.bbs import disconnect, getch
    import time
    import os
    session, term = getsession(), getterminal()
    session.activity = 'logging off'
    handle = session.user.handle or 'anonymous'
    echo(term.clear())
    echo(u''.join((u'\r\n\r\n', term.clear_eol,)))
    for line in showart(os.path.join(os.path.dirname(__file__), 'art', 'logoff.ans'), 'cp437'):
        echo(line)
    inp = getch(1)
    echo(unichr(27) + u'[23;0t')
    echo(u'bye ' + handle + '!\n')
    disconnect('logoff.')
Пример #25
0
Файл: ol.py Проект: hick/x84
def banner():
    """ Return centered banner """
    from x84.bbs import getterminal, showart
    import os
    term = getterminal()
    output = u''
    output += u'\r\n\r\n' + term.normal
    if term.width >= 78:
        artfile = os.path.join(os.path.dirname(__file__), 'art',
                               'oneliner.ans')
        artfilewidth = 80
    if term.width >= 100:
        artfile = os.path.join(os.path.dirname(__file__), 'art',
                               'oneliner100.ans')
        artfilewidth = 100

    output += term.home + term.normal + term.clear
    for line in showart(artfile, 'topaz'):
        output = output + term.move_x((term.width / 2) -
                                      artfilewidth / 2) + line
    return output + term.normal
Пример #26
0
def refresh_screen(term, again=False):
    # create a new, empty screen
    if again:
        echo(term.home + term.clear_eos)
    else:
        echo(term.move(term.height - 1, 0))
        echo(u'\r\n' * (term.height + 1))
    ans_height = 24
    ans_width = 78
    ypos, xpos = (max(0, int(math.floor(term.height / 2 - (ans_height / 2)))),
                  max(0, int(math.floor(term.width / 2 - (ans_width / 2)))))
    for y_offset, line in enumerate(showart(art_file, encoding=art_encoding)):
        _ypos = ypos + y_offset
        if _ypos <= term.height:
            echo(term.move(_ypos, xpos))
            echo(line)
    top_window = WindowDimension(
        yloc=ypos, xloc=xpos + 1, height=9, width=78)
    bot_window = WindowDimension(
        yloc=ypos + 14, xloc=xpos + 1, height=10, width=78)
    return top_window, bot_window
Пример #27
0
def banner():
    session, term = getsession(), getterminal()
    art_file = os.path.join(os.path.dirname(__file__), 'art', 'automsg.ans')
    echo(term.clear)
    for line in showart(art_file, 'topaz'):
        echo(line)

    if not os.path.exists(get_datafile_path()):
        with codecs.open(get_datafile_path(), 'w', 'utf-8') as fo:
            fo.write('big brother\n')
            fo.write('behave yourselves.\n')
            fo.write('\n\n')

    echo(term.move(12, 10) + term.blue(u'Public message from:'))

    with codecs.open(get_datafile_path(), 'r', 'utf-8') as fo:
        handle = fo.readline().strip()
        echo(term.move(12, 31) + term.bold_white(handle))
        for row in range(1, 4):
            echo(term.move(15 + row, 5) + term.white(fo.readline().strip()))

    ask(u'do you want to write a new public message? ')
Пример #28
0
def banner():
    session, term = getsession(), getterminal()
    art_file = os.path.join(os.path.dirname(__file__), 'art', 'automsg.ans')
    echo(term.clear)
    for line in showart(art_file,'topaz'):
        echo(line)

    if not os.path.exists(get_datafile_path()):
        with codecs.open(get_datafile_path(), 'w', 'utf-8') as fo:
            fo.write('big brother\n')
            fo.write('behave yourselves.\n')
            fo.write('\n\n')

    echo(term.move(12, 10) + term.blue(u'Public message from:'))

    with codecs.open(get_datafile_path(), 'r', 'utf-8') as fo:
        handle = fo.readline().strip()
        echo(term.move(12, 31) + term.bold_white(handle))
        for row in range(1, 4):
            echo(term.move(15 + row, 5) + term.white(fo.readline().strip()))

    ask(u'do you want to write a new public message? ')
Пример #29
0
def showansi(filename):
    for line in showart(
            os.path.dirname(__file__) + '../art/' + filename, 'topaz'):
        echo(line)
Пример #30
0
def banner():
    artfile = os.path.join(os.path.dirname(__file__), 'art', 'textbrowse.ans')
    banner = ''
    for line in showart(artfile, center=True):
        banner = banner + line
    return banner
Пример #31
0
def showansi(filename):
    for line in showart(os.path.dirname(__file__)+ '/art/'+filename, 'topaz'):
        echo(line)
Пример #32
0
def displayfile(filename):
    term = getterminal()
    session = getsession()
    asciitext = []
    text = []
    offset = 0
    quit = False
    istext = False
    dirty = True
    echo(term.clear)

    if os.path.splitext(filename)[1][1:].lower() == 'txt': # text files are opened with codecs
        file = codecs.open(filename,encoding='cp437')
        for line in file:
            text.append(line.rstrip())
        istext = True
    else:
        for line in showart(filename): # ansi / ascii files are opened with showart
            text.append(line)
    while not quit:
        if dirty:
            echo(term.move(0,0)+term.normal)
            for i in range (0, term.height-1):
                if len(text) > i+offset:
                    if istext == True: # atleast we can prevent text files from wrapping..
                        echo(term.clear_eol+term.move_x(max(0,(term.width/2)-40))+text[i+offset][:term.width]+'\r\n')
                    else:
                        echo(term.clear_eol+term.move_x(max(0,(term.width/2)-40))+text[i+offset])

        event, data = session.read_events(('input', 'refresh'))

        if event == 'refresh':
            echo(term.clear()) # to ensure there are no leftovers when resizing the window
            dirty = True
        if event == 'input':
            dirty = True
            session.buffer_input(data, pushback=True)
            inp = term.inkey(0)
            while inp:
                if inp.lower() == u'q' or inp.code == term.KEY_ESCAPE or inp.code == term.KEY_ENTER:
                    quit = True
                    break
                elif inp.code == term.KEY_HOME and offset > 0:
                    offset = 0
                elif inp.code == term.KEY_END and len(text) > term.height:
                    offset = len(text) - term.height+1
                elif inp.code == term.KEY_DOWN and len(text) > offset+term.height-1:
                    offset = offset + 1
                elif inp.code == term.KEY_UP and offset > 0:
                    offset = offset -1
                elif (inp.code == term.KEY_LEFT or inp.code == term.KEY_PGUP) and offset > 0:
                    if offset > term.height:
                        offset = offset - term.height+2
                    else:
                        offset = 0
                elif (inp.code == term.KEY_RIGHT or inp.code == term.KEY_PGDOWN) and offset+term.height-1 < len(text):
                    if (offset+term.height*2)-1 < len(text):
                        offset = offset + term.height-2
                    else:
                        offset = max(0, len(text) - term.height+1)
                else:
                    dirty = False
                inp = term.inkey(0)
Пример #33
0
def refresh():
    """ 显示主菜单"""
    logger = logging.getLogger()
    session, term = getsession(), getterminal()
    session.activity = u'Main menu'
    ### 读取的 ascii art 文件
    artfile = 'hick.asc'
    echo(u''.join((u'\r\n', term.blue(u'/'.rjust(term.width / 2)),
                   term.bold_black(u'/ '), term.bold('x'), term.bold_blue('/'),
                   term.bold('84'), u' ', u'主菜单', u'\r\n')))
    # displays a centered main menu header in topaz encoding for utf8
    for line in showart(
            os.path.join(os.path.dirname(__file__), 'art', artfile), 'topaz'):
        echo(term.cyan + term.move_x((term.width / 2) - 40) + line)
    echo(u'\r\n')
    ### 下面是主菜单
    entries = [
        ('$', u'查看公告'),
        ('b', u'站点穿梭'),
        # ('l', 'ASt CAllS'),
        # ('o', 'NE liNERS'),
        ('w', u"在线用户"),
        ('n', u'新闻列表'),
        # ('c', u'聊天室'),
        # ('i', u'IRC聊天'),
        ('!', u"编码调整\n"),
        ('t', u'测试调试'),
        # ('s', 'YS. iNfO'),
        # ('u', 'SER LiST'),
        # ('f', 'ORECASt'),
        ('e', u'个人资料'),
        ('p', u'发表文章'),
        ('r', u'查看消息'),
        # ('v', 'OTiNG bOOTH'),
        ('g', u'离开本站'),
    ]

    # add LORD to menu only if enabled: dosemu 模块后边了解下, 暂时保留
    if ini.CFG.getboolean(
            'dosemu',
            'enabled') and (ini.CFG.get('dosemu', 'lord_path') != 'no'):
        entries.insert(0, ('#', 'PlAY lORd!'))

    # add sesame doors to menu if enabled
    if ini.CFG.has_section('sesame'):
        from ConfigParser import NoOptionError
        for door in ini.CFG.options('sesame'):
            if '_' in door:
                continue

            # .. but only if we have the binary
            if not os.path.exists(ini.CFG.get('sesame', door)):
                continue

            # .. and a key is configured
            try:
                key = ini.CFG.get('sesame', '{}_key'.format(door))
            except NoOptionError:
                logger.error("no key configured for sesame door '{}'".format(
                    door, ))
            else:
                logger.debug("added sesame door '{}' with key '{}'".format(
                    door, key))
                entries.insert(0, (key, 'PlAY {}'.format(door)))

    ### 渲染输出主菜单
    buf_str = u''
    for key, name in entries:
        out_str = u''.join((term.bold(u'('), term.bold_blue_underline(key),
                            term.bold(u')'), term.bold_blue(name.split()[0]),
                            u' ', u' '.join(name.split()[1:]), u'  '))
        ansilen = term.length(buf_str + out_str)
        if ansilen >= (term.width * .8):
            echo(term.center(buf_str) + u'\r\n\r\n')
            buf_str = out_str
        else:
            # 每行换行
            echo(term.center(buf_str) + u'\r\n\r\n')
            buf_str = out_str

    echo(term.center(buf_str) + u'\r\n\r\n')
    echo(u' [%s]:' %
         (term.blue_underline(''.join([key for key, name in entries]))))
Пример #34
0
def main():
    session = getsession()
    session.activity = u'hanging out in voting script'
    term = getterminal()
    echo(term.clear())

    db = DBProxy(databasename)
    if not 'questions' in db:
        generate_database()

    while True:
        echo(
            term.clear())  # clears the screen and displays the vote art header
        for line in showart(
                os.path.join(os.path.dirname(__file__), 'art', 'vote.ans'),
                'topaz'):
            echo(term.cyan + term.move_x((term.width / 2) - 40) + line)

        if 'sysop' in session.user.groups:
            spacing = 1
        else:
            spacing = 7
            echo(' ')
        echo(term.magenta + '\n (' + term.cyan + 'r' + term.magenta + ')' +
             term.white + 'esults' + ' ' * spacing)
        echo(term.magenta + '(' + term.cyan + 'v' + term.magenta + ')' +
             term.white + 'ote on a question' + ' ' * spacing)
        echo(term.magenta + '(' + term.cyan + 'a' + term.magenta + ')' +
             term.white + 'dd a new question' + ' ' * spacing)
        if 'sysop' in session.user.groups:
            echo(term.magenta + '(' + term.cyan + 'd' + term.magenta + ')' +
                 term.white + 'elete a question' + ' ' * spacing)
        echo(term.magenta + '(' + term.cyan + 'q' + term.magenta + ')' +
             term.white + 'uit')
        echo(term.magenta + '\r\n\r\n\r\nx/84 voting booth command: ')
        le = LineEditor(30)
        le.colors['highlight'] = term.cyan
        inp = le.read()
        inp = inp.lower(
        )  # makes the input indifferent to wheter you used lower case when typing in a command or not..

        if 'sysop' in session.user.groups and inp == 'd':
            while 1:
                questionnumber = query_question()
                if questionnumber == 999:
                    break
                delete_question(questionnumber)
        elif inp == 'r':
            while 1:
                questionnumber = query_question()
                if questionnumber == 999:
                    break
                list_results(questionnumber)
        elif inp == 'v':
            while 1:
                questionnumber = query_question()
                if questionnumber == 999:
                    break
                vote(questionnumber)
        elif inp == 'a':
            add_question()
        elif inp == 'q':
            return
        else:
            echo(term.red + '\r\nNo such command. Try again.\r\n'
                 )  # if no valid key is pressed then do some ami/x esthetics.
            waitprompt()
Пример #35
0
def main():
    session = getsession()
    session.activity = u'hanging out in voting script'
    term = getterminal()
    echo(syncterm_setfont('topaz'))

    db = DBProxy(databasename)
    if 'questions' not in db:
        generate_database()

    while True:
        # clears the screen and displays the vote art header
        echo(term.clear())
        for line in showart(
                os.path.join(os.path.dirname(__file__), 'art', 'vote.ans'), 'cp437'):
            echo(term.cyan + term.move_x(max(0, (term.width / 2) - 40)) + line)

        if 'sysop' in session.user.groups:
            spacing = 1
        else:
            spacing = 7
            echo(' ')
        echo(term.magenta(u'\n (') + term.cyan(u'r') + term.magenta(u')') +
             term.white(u'esults') + ' ' * spacing +
             term.magenta(u'(') + term.cyan(u'v') + term.magenta(u')') +
             term.white(u'ote on a question') + u' ' * spacing +
             term.magenta(u'(') + term.cyan(u'a') + term.magenta(u')') +
             term.white(u'dd a new question') + u' ' * spacing)
        if 'sysop' in session.user.groups:
            echo(term.magenta(u'(') + term.cyan(u'd') + term.magenta(u')') +
                 term.white(u'elete a question') + u' ' * spacing)
        echo(term.magenta(u'(') + term.cyan(u'q') + term.magenta(u')') + term.white(u'uit') +
             term.magenta(u'\r\n\r\nx/84 voting booth command: '))
        le = LineEditor(10)
        le.colors['highlight'] = term.cyan
        inp = le.read()
        # makes the input indifferent to wheter you used lower case when typing
        # in a command or not..
        inp = (inp or u'').lower()

        if 'sysop' in session.user.groups and inp == u'd':
            while True:
                questionnumber = query_question()
                if questionnumber == -1:
                    break
                delete_question(questionnumber)
        elif inp == u'r':
            while True:
                questionnumber = query_question()
                if questionnumber == -1:
                    break
                list_results(questionnumber)
        elif inp == u'v':
            while True:
                questionnumber = query_question()
                if questionnumber == -1:
                    break
                vote(questionnumber)
        elif inp == u'a':
            add_question()
        elif inp == u'q':
            return
        else:
            # if no valid key is pressed then do some ami/x esthetics.
            echo(term.red(u'\r\nNo such command. Try again.\r\n'))
            waitprompt(term)
Пример #36
0
def renderscreen(menudraw=True, artdraw=True, bgdraw=True, tall=False, wide=False, widgets=['clock',],):
    global menutoggle
    global arttoggle
    global bgtoggle
    global walltime
    """ Rendering routine for the current screen. """
    # This is where we depart. We want a clean windowing scheme
    # with a background layer, modular construction and incremental update ability.
    # In theory we should have separate content-generating and screen-rendering subs
    # to provide for fast refreshes without stutters, but that will have to come later.
    from x84.bbs import AnsiWindow, getsession, getterminal, echo, ini, showart
    import os, time, random, glob
    session, term = getsession(), getterminal()
    colors = {}
    colors['border'] = term.green
    #lets start with the bg frame
    headers = glob.glob(os.path.join(here,"art","top","*.*"))
    background = AnsiWindow(term.height - 1, term.width, 0, 0)
    background.init_theme(colors, None, 'block')
    echo(term.clear())
    ypos = 1
    art_file = session.user['bg']
    linelist = []
    for line in showart(art_file, encoding=art_encoding,):
	if ypos >= term.height - 2:
	    break
	linelist.append(line)
        ypos += 1
	#echo(background.pos(ypos, 1)+line)
    if len(linelist) < background.height - 1:
       ypos = int(((background.height - len(linelist)) / 2) + 1)
    else:
       ypos = 1
    for i in linelist:
        echo(background.pos(ypos, 1))
        echo(i)
	ypos += 1
    echo(background.border())
#	    fillwindow(background,  chr(176).decode('cp437'), True)
  
    #now on to the top art
    if artdraw:
	    toparty = 3
	    topartx = 3
	    topartheight = 9
	    topartwidth = 37
	    topart = AnsiWindow(topartheight, topartwidth, toparty, topartx)
	    topart.init_theme(colors, None, 'block')
	    echo (topart.clear())
	    ypos = 1
	    bannername = "yos.asc"
	    #bannername = "YOSBBS"+str(random.randrange(1,35)).zfill(2)+".ANS"
	    art_file = os.path.join(os.path.dirname(__file__), 'art', bannername)
	    for line in showart(art_file, encoding=art_encoding):
		echo(topart.pos(ypos, 2)+line)
		ypos += 1
            colors['border'] = term.green
            topart.init_theme(colors, None, 'shadow')
            echo(topart.border() + topart.title(str(time.time()))) 
    if menudraw:
	    rendermenuwin()
    return art_file
Пример #37
0
def refresh():
    """ Refresh main menu. """
    # pylint: disable=R0914
    #         Too many local variables
    from x84.bbs import getsession, getterminal, echo, showart, ini
    import os
    import logging
    logger = logging.getLogger()
    session, term = getsession(), getterminal()
    session.activity = u'Main menu'
    artfile = os.path.join(os.path.dirname(__file__), 'art', 'main.asc')
    echo(u''.join((
        u'\r\n\r\n',
        term.blue(u'/'.rjust(term.width / 2)), term.bold_black(u'/ '),
        term.bold('x'), term.bold_blue('/'), term.bold('84'), u' ',
        'MAiN MENU',
        u'\r\n')))
    # displays a centered main menu header in topaz encoding for utf8
    for line in showart(artfile,'topaz'):
        echo(term.cyan+term.move_x((term.width/2)-40)+line)
    echo(u'\r\n\r\n')
    entries = [
        ('$', 'rEAD bUllETiNS'),
        ('b', 'bS NEXUS'),
        ('l', 'ASt CAllS'),
        ('o', 'NE liNERS'),
        ('w', "hO'S ONliNE"),
        ('n', 'EWS'),
        ('c', 'hAt'),
        ('i', 'RC chAt'),
        ('!', 'ENCOdiNG'),
        ('t', 'EtRiS'),
        ('s', 'YS. iNfO'),
        ('u', 'SER LiST'),
        ('f', 'ORECASt'),
        ('e', 'dit PROfilE'),
        ('p', 'OSt A MSG'),
        ('r', 'EAd All MSGS'),
        ('g', 'OOdbYE /lOGOff'),]

    # add LORD to menu only if enabled,
    if ini.CFG.getboolean('dosemu', 'enabled') and (
            ini.CFG.get('dosemu', 'lord_path') != 'no'):
        entries.insert(0, ('#', 'PlAY lORd!'))

    # add sesame doors to menu if enabled
    if ini.CFG.has_section('sesame'):
        from ConfigParser import NoOptionError
        for door in ini.CFG.options('sesame'):
            if '_' in door:
                continue

            # .. but only if we have the binary
            if not os.path.exists(ini.CFG.get('sesame', door)):
                continue

            # .. and a key is configured
            try:
                key = ini.CFG.get('sesame', '{}_key'.format(door))
            except NoOptionError:
                logger.error("no key configured for sesame door '{}'".format(
                    door,
                ))
            else:
                logger.debug("added sesame door '{}' with key '{}'".format(
                    door, key
                ))
                entries.insert(0, (key, 'PlAY {}'.format(door)))

    buf_str = u''
    for key, name in entries:
        out_str = u''.join((
            term.bold(u'('),
            term.bold_blue_underline(key),
            term.bold(u')'),
            term.bold_blue(name.split()[0]),
            u' ', u' '.join(name.split()[1:]),
            u'  '))
        ansilen = term.length(buf_str + out_str)
        if ansilen >= (term.width * .8):
            echo(term.center(buf_str) + u'\r\n\r\n')
            buf_str = out_str
        else:
            buf_str += out_str
    echo(term.center(buf_str) + u'\r\n\r\n')
    echo(u' [%s]:' % (
        term.blue_underline(''.join([key for key, name in entries]))))
Пример #38
0
def refresh():
    """ Refresh main menu. """
    # pylint: disable=R0914
    #         Too many local variables
    from x84.bbs import getsession, getterminal, echo, showart, ini
    import os
    import logging
    logger = logging.getLogger()
    session, term = getsession(), getterminal()
    session.activity = u'Main menu'
    artfile = 'main*.asc'
    echo(u''.join((u'\r\n\r\n', term.blue(u'/'.rjust(term.width / 2)),
                   term.bold_black(u'/ '), term.bold('x'), term.bold_blue('/'),
                   term.bold('84'), u' ', 'MAiN MENU', u'\r\n')))
    # displays a centered main menu header in topaz encoding for utf8
    for line in showart(
            os.path.join(os.path.dirname(__file__), 'art', artfile), 'topaz'):
        echo(term.cyan + term.move_x((term.width / 2) - 40) + line)
    echo(u'\r\n\r\n')
    entries = [
        ('$', 'rEAD bUllETiNS'),
        ('b', 'bS NEXUS'),
        ('l', 'ASt CAllS'),
        ('o', 'NE liNERS'),
        ('w', "hO'S ONliNE"),
        ('n', 'EWS'),
        ('c', 'hAt'),
        ('i', 'RC chAt'),
        ('!', 'ENCOdiNG'),
        ('t', 'EtRiS'),
        ('s', 'YS. iNfO'),
        ('u', 'SER LiST'),
        ('f', 'ORECASt'),
        ('e', 'dit PROfilE'),
        ('p', 'OSt A MSG'),
        ('r', 'EAd All MSGS'),
        ('v', 'OTiNG bOOTH'),
        ('g', 'OOdbYE /lOGOff'),
    ]

    # add LORD to menu only if enabled,
    if ini.CFG.getboolean(
            'dosemu',
            'enabled') and (ini.CFG.get('dosemu', 'lord_path') != 'no'):
        entries.insert(0, ('#', 'PlAY lORd!'))

    # add sesame doors to menu if enabled
    if ini.CFG.has_section('sesame'):
        from ConfigParser import NoOptionError
        for door in ini.CFG.options('sesame'):
            if '_' in door:
                continue

            # .. but only if we have the binary
            if not os.path.exists(ini.CFG.get('sesame', door)):
                continue

            # .. and a key is configured
            try:
                key = ini.CFG.get('sesame', '{}_key'.format(door))
            except NoOptionError:
                logger.error("no key configured for sesame door '{}'".format(
                    door, ))
            else:
                logger.debug("added sesame door '{}' with key '{}'".format(
                    door, key))
                entries.insert(0, (key, 'PlAY {}'.format(door)))

    buf_str = u''
    for key, name in entries:
        out_str = u''.join((term.bold(u'('), term.bold_blue_underline(key),
                            term.bold(u')'), term.bold_blue(name.split()[0]),
                            u' ', u' '.join(name.split()[1:]), u'  '))
        ansilen = term.length(buf_str + out_str)
        if ansilen >= (term.width * .8):
            echo(term.center(buf_str) + u'\r\n\r\n')
            buf_str = out_str
        else:
            buf_str += out_str
    echo(term.center(buf_str) + u'\r\n\r\n')
    echo(u' [%s]:' %
         (term.blue_underline(''.join([key for key, name in entries]))))