本文整理汇总了Python中x84.bbs.echo函数的典型用法代码示例。如果您正苦于以下问题:Python echo函数的具体用法?Python echo怎么用?Python echo使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了echo函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: describe_ssh_availability
def describe_ssh_availability(term, session):
from x84.bbs.ini import CFG
if session.kind == 'ssh':
# what a good citizen!
return
if not (CFG.has_section('ssh') and
not CFG.has_option('ssh', 'enabled')
or CFG.getboolean('ssh', 'enabled')):
# ssh not enabled
return
about_key = (u"You may even use an ssh key, which you can configure from "
u"your user profile, " if not session.user.get('pubkey')
else u'')
big_msg = term.bold_blue("Big Brother is Watching You")
description = (
" {term.red}You are using {session.kind}, but ssh is available "
"on port {ssh_port} of this server. If you want a secure connection "
"with shorter latency, we recommend instead to use ssh! {about_key}"
"Remember: {big_msg}!"
.format(term=term,
session=session,
ssh_port=ssh_port,
about_key=about_key,
big_msg=big_msg)
)
echo(u'\r\n\r\n')
for txt in term.wrap(description, width=min(80, term.width)):
echo(term.move_x(max(0, (term.width // 2) - 40)))
echo(term.red(txt.rstrip() + '\r\n'))
echo(u'\r\n\r\n')
echo(term.center(term.bold_black('Press any key to continue: ')).rstrip())
term.inkey()
示例2: prompt_ok
def prompt_ok():
"""
Prompt user to continue, True if they select yes.
"""
from x84.bbs import getsession, getterminal, echo, getch, Selector
session, term = getsession(), getterminal()
prompt_confirm = u'EVERYthiNG lOOk Ok ?'
prompt_continue = u'YES (CONtiNUE)'
prompt_chg = u'NO! (ChANGE)'
def prompt_ok_dumb():
""" Dummy terminal prompt for confirm/cancel. """
echo('\r\n\r\n%s\r\n' % (prompt_confirm,))
echo('1 - %s\r\n' % (prompt_continue,))
echo('2 - %s\r\n\r\n' % (prompt_chg,))
echo('select (1, 2) --> ')
while True:
inp = getch()
if inp == u'1':
return True
elif inp == u'2':
return False
if session.env.get('TERM') == 'unknown':
return prompt_ok_dumb()
sel = Selector(yloc=term.height - 1, xloc=5,
width=term.width - 10,
left=prompt_continue, right=prompt_chg)
echo(term.normal)
echo(term.move(term.height - 2, 0) + term.clear_eol)
echo(prompt_confirm.center(term.width - 1) + '\r\n')
echo(term.clear_eol + sel.refresh())
while True:
echo(sel.process_keystroke(getch()))
if sel.selected:
return True if sel.selection == prompt_continue else False
示例3: redrawlightbar
def redrawlightbar(filer, lighty,lightx,lightbar,start,antalrader): # if the variable lightbar is negative the lightbar will be invisible
import time
from x84.bbs import timeago
term = getterminal()
echo(term.move(lighty,lightx))
for i in range (0, term.height - 2):
echo(term.move(lighty+i,lightx)+u' '*(term.width - lightx)) # erases 60 char. dont want to use clreol. So filenames/directories can be 45 char.
i2 = 0
for i in range (start,start+antalrader):
origtime = filer[i][6].strip()
secsago = timeago(time.time() - (3600 * 6)- time.mktime(time.strptime(origtime,"%I:%M %p %b %d, %Y")))
# if secsago[-1] == 's':
secsago = secsago[:-3]
secsago = u''.join([ u' ' * (5-len(secsago)), secsago ])
rightbar = filer[i][5].rjust(19)+u' '+ str(secsago)
leftbar = filer[i][1][:term.width - len(rightbar) - 5]
if i2 == lightbar:
echo(term.move(lighty+i-start-1,lightx)+term.blue_reverse+leftbar[:10]+term.normal)
else:
echo(term.move(lighty+i-start-1,lightx)+term.white+leftbar[:10]+term.normal)
echo(term.move(lighty+i-start-1,term.width - len(rightbar) - 2)+rightbar+term.normal)
i2 = i2 + 1
示例4: refresh
def refresh():
""" Refresh screen and return top-left (x, y) location. """
# set syncterm font to cp437
if term.kind.startswith('ansi'):
echo(syncterm_setfont('cp437'))
echo(u'\r\n\r\n')
if term.width < width:
echo(u''.join((
term.move(term.height, 0),
u'\r\n\r\n',
term.bold_red + 'screen too thin! (%s/%s)' % (
term.width, width,),
u'\r\n\r\n',
u'press any key...',)))
getch()
return (None, None)
if term.height < height:
echo(u''.join((
term.move(term.height, 0),
u'\r\n\r\n',
term.bold_red + 'screen too short! (%s/%s)' % (
term.height, height),
u'\r\n\r\n',
u'press any key...',)))
getch()
return (None, None)
xloc = (term.width / 2) - (width / 2)
yloc = (term.height / 2) - (height / 2)
echo(u''.join((
term.normal,
(u'\r\n' + term.clear_eol) * term.height,
u''.join([term.move(yloc + abs_y, xloc) + line
for abs_y, line in enumerate(otxt)]),)))
return xloc, yloc
示例5: main
def main():
session, term = getsession(), getterminal()
session.activity = 'Viewing Userlist'
colors = {'highlight': term.red,
'lowlight': term.green, }
line_no = display_banner(filepattern=art_file, encoding=art_encoding)
# get and format userlist
userlist = (
u'{sp}{handle} {location} {lastcall}'
.format(sp=u' ' * 4,
handle=ur.handle.ljust(username_max_length),
location=colors['lowlight'](
ur.location.ljust(location_max_length)),
lastcall=timeago(ur.timeago))
for ur in iter_userlist())
echo(u'\r\n')
# display users, using a command-prompt pager.
prompt_pager(content=userlist,
line_no=line_no + 1,
colors={'highlight': term.red,
'lowlight': term.green,
},
width=80, breaker=None)
示例6: 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
示例7: redraw
def redraw(pager, selector):
""" Redraw pager and selector """
from x84.bbs import getsession, getterminal, echo
session, term = getsession(), getterminal()
session.flush_event('oneliner_update')
pager.colors['border'] = term.white
pager.glyphs['top-horiz'] = u''
pager.glyphs['top-right'] = u''
pager.glyphs['top-left'] = u''
pager.glyphs['bot-horiz'] = u''
pager.glyphs['bot-right'] = u''
pager.glyphs['bot-left'] = u''
pager.glyphs['left-vert'] = u''
pager.glyphs['right-vert'] = u''
prompt_ole = u'write an oneliner?'
pager.update(u'\n\n\nFetching ...')
echo(u''.join((
pager.refresh(),
pager.border(),
term.move(selector.yloc - 2, selector.xloc),
term.bold_red(prompt_ole.center(selector.width).rstrip()),
term.clear_eol,
selector.refresh(),)))
pager.update(u'\n'.join(get_oltxt()))
pager.move_end()
echo(pager.refresh())
示例8: main
def main(handle=None):
""" Main procedure. """
# pylint: disable=R0914,R0912,R0915
# Too many local variables
# Too many branches
# Too many statements
session, term = getsession(), getterminal()
session.activity = 'top'
# attempt to coerce encoding of terminal to match session.
coerce_terminal_encoding(term, session.encoding)
# fetch user record
user = get_user_record(handle)
# register call
login(session, user)
# display art and prompt for quick login
quick = do_intro_art(term, session)
echo(term.move_down() * 3)
# only display news if the account has not
# yet read the news since last update.
gosub('news', quick=True)
if not quick:
# display last 10 callers, if any
gosub('lc')
# one-liners
gosub('ol')
goto('main')
示例9: refresh_automsg
def refresh_automsg(idx):
""" Refresh automsg database, display automsg of idx, return idx. """
session.flush_event('automsg')
autodb = DBProxy('automsg')
automsgs = sorted(autodb.values()) if len(autodb) else db_firstrecord
dblen = len(automsgs)
# bounds check
if idx < 0:
idx = dblen - 1
elif idx > dblen - 1:
idx = 0
tm_ago, handle, msg = automsgs[idx]
asc_ago = u'%s ago' % (timeago(time.time() - tm_ago))
disp = (u''.join(('\r\n\r\n',
term.bold(handle.rjust(max_user)),
term.bold_blue(u'/'),
term.blue(u'%*d' % (len('%d' % (dblen,)), idx,)),
term.bold_blue(u':'),
term.blue_reverse(msg.ljust(automsg_len)),
term.bold(u'\\'),
term.blue(asc_ago),)))
echo(u''.join((
u'\r\n\r\n',
Ansi(disp).wrap(term.width),
)))
return idx
示例10: pak
def pak():
""" Press any key prompt. """
from x84.bbs import echo, getch
msg_pak = u'PRESS ANY kEY'
echo(u'\r\n%s ... ' % (msg_pak,))
getch()
return
示例11: get_article
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
示例12: try_pass
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'\r\n\r\n pass: '
status_auth = u'\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(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
示例13: send_passkey
def send_passkey(user):
""" Send passkey token to user by e-mail. """
session = getsession()
passkey = base64.encodestring(os.urandom(50))[:password_max_length]
email_msg = MIMEText(msg_mailbody.format(bbsname=system_bbsname,
session=session,
user=user,
passkey=passkey))
email_msg['From'] = msg_mailfrom
email_msg['To'] = user.email
email_msg['Subject'] = msg_mailsubj.format(bbsname=system_bbsname)
try:
smtp = smtplib.SMTP(mail_smtphost)
smtp.sendmail(msg_mailfrom, [user.email], email_msg.as_string())
smtp.quit()
except Exception as err:
log.exception(err)
echo('{0}'.format(err))
return False
log.info(u'Password reset token delivered '
u'to address {0!r} for user {1!r}.'
.format(user.email, user.handle))
return passkey
示例14: main
def main():
""" main entry point. """
from x84.bbs import getterminal, getsession, echo
session, term = getsession(), getterminal()
session.activity = 'looking for a place to drink at'
# 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))
while True:
disp_search_help()
search = get_city()
if search is None or 0 == len(search):
return
item = do_get_random_item(search)
display_suggestion(item)
while True:
# allow re-displaying weather between C/F, even at EOT prompt
inp = term.inkey()
if inp.lower() == cf_key:
get_centigrade()
break
elif inp.code == term.KEY_ENTER:
return
示例15: show_description
def show_description(term, description, color='white', width=80, **kwargs):
"""
Display text as given ``color``, left-adjusted ``width``.
:param str description: description text, may contain terminal attributes,
in which case ``color`` should be set to None.
:param str color: terminal color attribute name, may be None.
:param int width: left-adjusted width, if this is greater than the current
terminal's width, the terminal's width is used instead.
:param kwargs: all remaining keyword arguments are passed to the built-in
:class:`textwrap.TextWrapper`.
:rtype: int
:returns: number if lines written
"""
wide = min(width, term.width)
xpos = max(0, (term.width // 2) - (wide // 2))
lines = []
for line in unicode(description).splitlines():
if line.strip():
lines.extend(term.wrap(line, wide, **kwargs))
else:
lines.append(u'')
# output as a single string, reducing latency
outp = u''.join(
[getattr(term, color) if color else u''] +
[u''.join((
term.move_x(xpos) if xpos else u'',
txt.rstrip(),
term.clear_eol,
u'\r\n')) for txt in lines])
echo(outp)
return len(outp.splitlines())