本文整理汇总了Python中x84.bbs.getterminal函数的典型用法代码示例。如果您正苦于以下问题:Python getterminal函数的具体用法?Python getterminal怎么用?Python getterminal使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了getterminal函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: yes_no
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
示例2: main
def main(anonymous=False, new=False):
"""
Script entry point.
This is the default login matrix for the bbs system.
It takes no arguments or keyword arguments, because it assumes
the user should now be authenticated, such as occurs for example
on telnet.
"""
term = getterminal()
display_banner(term)
if anonymous:
# user rlogin'd in as [email protected]
goto(top_script, 'anonymous')
elif new:
# user rlogin'd in as [email protected]
goto(new_script)
# do_login will goto/gosub various scripts, if it returns, then
# either the user entered 'bye', or had too many failed attempts.
do_login(term)
log.debug('Disconnecting.')
# it is necessary to provide sufficient time to send any pending
# output across the transport before disconnecting.
term.inkey(1.5)
示例3: chk_save_location
def chk_save_location(location):
"""
Prompt user to save location for quick re-use
"""
from x84.bbs import getterminal, getsession, echo, getch
session, term = getsession(), getterminal()
stored_location = session.user.get('location', dict()).items()
if (sorted(location.items()) == sorted(stored_location)):
# location already saved
return
if session.user.handle == 'anonymous':
# anonymous cannot save preferences
return
# prompt to store (unsaved/changed) location
echo(u'\r\n\r\n')
echo(term.yellow(u'Save Location'))
echo(term.bold_yellow(u' ('))
echo(term.bold_black(u'private'))
echo(term.bold_yellow(u') '))
echo(term.yellow(u'? '))
echo(term.bold_yellow(u'['))
echo(term.underline_yellow(u'yn'))
echo(term.bold_yellow(u']'))
echo(u': ')
while True:
inp = getch()
if inp is None or inp in (u'n', u'N', u'q', u'Q', term.KEY_EXIT):
break
if inp in (u'y', u'Y', u' ', term.KEY_ENTER):
session.user['location'] = location
break
示例4: display_banner
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
示例5: display_msg
def display_msg(msg):
""" Display full message """
from x84.bbs import getterminal, getsession, echo, decode_pipe
session, term = getsession(), getterminal()
body = msg.body.splitlines()
style = getstyle()
receipt = (msg.recipient if msg.recipient is not None
else u'<(None)=All users>')
echo(u' AUthOR: ' + style['highlight'](msg.author) + u'\r\n\r\n')
echo(u' RECiPiENt: ')
echo(style['lowlight'](receipt))
echo(u'\r\n\r\n')
echo(u' SUBjECt: ')
echo(style['lowlight'](msg.subject))
echo(u'\r\n\r\n')
echo(u' tAGS: ')
echo(style['lowlight'](u', '.join(msg.tags)))
echo(u'\r\n\r\n')
echo(term.underline(u' bOdY: '.ljust(term.width - 1)) + u'\r\n')
echo(decode_pipe(u'\r\n'.join(body)) + term.normal)
echo(u'\r\n' + term.underline(u''.ljust(term.width - 1)))
echo(u'\r\n\r\n')
session.activity = 'Constructing a %s message' % (
u'public' if u'public' in msg.tags else u'private',)
return
示例6: main
def main(handle=u''):
""" Main procedure. """
# pylint: disable=R0914
# Too many local variables
from x84.bbs import getsession, getterminal, echo, ini, User, goto
from x84.bbs import showcp437
session, term = getsession(), getterminal()
import os
session.activity = u'Applying for an account'
artfile = os.path.join(os.path.dirname(__file__), 'art', 'nua.asc')
msg_header = u'NEW USER APPliCAtiON'
# pylint: disable=E1103
# Instance of '_Chainmap' has no 'split' member
# (but some types could not be inferred)
newcmds = ini.CFG.get('matrix', 'newcmds').split()
topscript = ini.CFG.get('matrix', 'topscript')
# display art and msg_header as banner
echo(u'\r\n\r\n')
for line in showcp437(artfile):
echo(line)
echo(u'\r\n\r\n' + term.reverse + msg_header.center(term.width))
# create new user record for manipulation
user = User(handle if handle.lower() not in newcmds else u'')
while True:
set_handle(user)
set_location(user)
set_email(user)
set_password(user)
set_sacookies(user)
if prompt_ok():
user.save()
goto(topscript, user.handle)
示例7: set_password
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: '
prompt_verify = u' 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
示例8: add_comment
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()
示例9: chk_save_location
def chk_save_location(location):
"""
Prompt user to save location for quick re-use
"""
from x84.bbs import getterminal, getsession, echo, getch
session, term = getsession(), getterminal()
stored_location = session.user.get('location', dict()).items()
if (sorted(location.items()) == sorted(stored_location)):
return
# prompt to store (unsaved/changed) location
echo(u'\r\n\r\n')
echo(term.yellow(u'SAVE lOCAtION'))
echo(term.bold_yellow(' ('))
echo(term.bold_black(u'PRiVAtE'))
echo(term.bold_yellow(') '))
echo(term.yellow('? '))
echo(term.bold_yellow(u'['))
echo(term.underline_yellow(u'yn'))
echo(term.bold_yellow(u']'))
echo(u': ')
while True:
inp = getch()
if inp is None or inp in (u'n', u'N', u'q', u'Q', term.KEY_EXIT):
break
if inp in (u'y', u'Y', u' ', term.KEY_ENTER):
session.user['location'] = location
break
示例10: get_centigrade
def get_centigrade():
"""
Blocking prompt for setting C/F preference
"""
from x84.bbs import getterminal, getsession, echo, getch
term = getterminal()
session = getsession()
echo(u'\r\n\r\n')
echo(term.yellow(u'CElCiUS'))
echo(term.bold_yellow(u'('))
echo(term.bold_yellow_reverse(u'C'))
echo(term.bold_yellow(u')'))
echo(u' or ')
echo(term.yellow(u'fAhRENhEit'))
echo(term.bold_yellow(u'('))
echo(term.bold_yellow_reverse(u'F'))
echo(term.bold_yellow(u')'))
echo('? ')
while True:
inp = getch()
if inp in (u'c', u'C'):
session.user['centigrade'] = True
session.user.save()
break
elif inp in (u'f', u'F'):
session.user['centigrade'] = False
session.user.save()
break
elif inp in (u'q', u'Q', term.KEY_EXIT):
break
示例11: get_centigrade
def get_centigrade():
""" Blocking prompt for setting C/F preference. """
from x84.bbs import getterminal, getsession, echo
term = getterminal()
session = getsession()
if bool(session.user.handle == 'anonymous'):
# anonymous cannot set a preference.
return
echo(u''.join((
u'\r\n\r\n',
term.yellow(u'Celcius'),
term.bold_yellow(u'('),
term.bold_yellow_reverse(u'C'),
term.bold_yellow(u')'),
u' or ',
term.yellow(u'Fahrenheit'),
term.bold_yellow(u'('),
term.bold_yellow_reverse(u'F'),
term.bold_yellow(u')'),
u'? ')))
while True:
inp = term.inkey()
if inp in (u'c', u'C'):
session.user['centigrade'] = True
session.user.save()
break
elif inp in (u'f', u'F'):
session.user['centigrade'] = False
session.user.save()
break
elif inp in (u'q', u'Q', term.KEY_EXIT):
break
示例12: displayfile
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
示例13: display_banner
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
示例14: main
def main(anonymous=False, new=False, username=''):
""" Main procedure. """
from x84.bbs import (
getsession,
getterminal,
find_user,
get_user,
User,
)
session, term = getsession(), getterminal()
session.activity = 'sftp'
if anonymous:
user = User(u'anonymous')
else:
assert not new, ("[email protected] user not supported by SFTP.")
# ProperCase user-specified handle
handle = find_user(username)
assert handle is not None, handle
# fetch user record
user = get_user(handle)
# assign session user, just as top.py function login()
session.user = user
while True:
inp = term.inkey() # should block indefinately
log = logging.getLogger(__name__)
log.warn('Got inkey: {0!r}'.format(inp))
示例15: prompt
def prompt():
"""
Return string suitable for displaying prompt and available commands.
"""
from x84.bbs import getsession, getterminal
session, term = getsession(), getterminal()
decorate = lambda key, desc: u"".join(
(u"(", term.magenta_underline(key), u")", term.cyan(desc.split()[0]), u" ", u" ".join(desc.split()[1:]), u" ")
)
return term.wrap(
u"".join(
(
u" " * 2,
term.green_reverse(":keys"),
u" ",
decorate("c", "hAt USR"),
decorate("s", "ENd MSG"),
(
u"".join(
(decorate("d", "iSCONNECt SiD"), decorate("e", "diT USR"), decorate("v", "iEW SiD AttRS"), u" ")
)
if "sysop" in session.user.groups
else u""
),
decorate("Escape/q", "Uit"),
decorate("Spacebar", "REfRESh"),
)
),
int(term.width * 0.8),
subsequent_indent=u" " * 8,
)