def main(ttyfile=u'', peek=False): """ Main procedure. """ from x84.bbs import Lightbar, getch, getsession, getterminal, ini, echo # pylint: disable=R0914,R0915 # Too many local variables # Too many statements ttyplay_exe = ini.CFG.get('ttyplay', 'exe') if not os.path.exists(ttyplay_exe): echo(u'\r\n%s NOt iNStAllEd.\r\n' % (ttyplay_exe, )) getch() return session, term = getsession(), getterminal() # pylint: disable=W0212 # Access to a protected member _record_tty of a client class resume_rec = session._record_tty and session.is_recording if resume_rec: session.stop_recording() session._record_tty = False if 'sysop' in session.user.groups and ttyfile == u'': # pylint: disable=W0212 # Access to a protected member _ttyrec_folder of a client class folder = os.path.dirname(ttyfile) or session._ttyrec_folder pos = None while True: files = sorted([ fn for fn in os.listdir(session._ttyrec_folder) if fn.endswith('.ttyrec') ]) echo(u'\r\n' * term.height) sel = Lightbar(term.height - 1, term.width - 1, 0, 0) sel.colors['border'] = term.bold_green echo(sel.border() + sel.title('- SElECt A RECORdiNG -')) sel.update([(fname, fname) for fname in files]) if pos is not None: sel.position = pos x_ttyfile = sel.read() if x_ttyfile is None or sel.quit: break pos = sel.position ttyfile = os.path.join(folder, x_ttyfile) playfile(ttyplay_exe, ttyfile, peek) else: playfile(ttyplay_exe, ttyfile, peek) if not session.is_recording and resume_rec: session._record_tty = True session.start_recording() echo(term.move(term.height, 0)) echo(u'\r\n')
def main(ttyfile=u'', peek=False): """ Main procedure. """ from x84.bbs import Lightbar, getch, getsession, getterminal, ini, echo # pylint: disable=R0914,R0915 # Too many local variables # Too many statements ttyplay_exe = ini.CFG.get('ttyplay', 'exe') if not os.path.exists(ttyplay_exe): echo(u'\r\n%s NOt iNStAllEd.\r\n' % (ttyplay_exe,)) getch() return session, term = getsession(), getterminal() # pylint: disable=W0212 # Access to a protected member _record_tty of a client class resume_rec = session._record_tty and session.is_recording if resume_rec: session.stop_recording() session._record_tty = False if 'sysop' in session.user.groups and ttyfile == u'': # pylint: disable=W0212 # Access to a protected member _ttyrec_folder of a client class folder = os.path.dirname(ttyfile) or session._ttyrec_folder pos = None while True: files = sorted([fn for fn in os.listdir(session._ttyrec_folder) if fn.endswith('.ttyrec')]) echo(u'\r\n' * term.height) sel = Lightbar(term.height - 1, term.width - 1, 0, 0) sel.colors['border'] = term.bold_green echo(sel.border() + sel.title('- SElECt A RECORdiNG -')) sel.update([(fname, fname) for fname in files]) if pos is not None: sel.position = pos x_ttyfile = sel.read() if x_ttyfile is None or sel.quit: break pos = sel.position ttyfile = os.path.join(folder, x_ttyfile) playfile(ttyplay_exe, ttyfile, peek) else: playfile(ttyplay_exe, ttyfile, peek) if not session.is_recording and resume_rec: session._record_tty = True session.start_recording() echo(term.move(term.height, 0)) echo(u'\r\n')
def chose_location_lightbar(locations): """ Lightbar pager for chosing a location. """ from x84.bbs import getterminal, echo, Lightbar term = getterminal() fmt = u'%(city)s, %(state)s' lookup = dict([(loc['postal'], loc) for loc in locations]) fullheight = min(term.height - 8, len(locations) + 2) fullwidth = min(75, int(term.width * .8)) # shrink window to minimum width maxwidth = max([len(fmt % val) for val in lookup.values()]) + 2 if maxwidth < fullwidth: fullwidth = maxwidth echo(u'\r\n' * fullheight) lightbar = Lightbar(height=fullheight, width=fullwidth, yloc=term.height - fullheight, xloc=int((term.width / 2) - (fullwidth / 2))) lightbar.update([(key, fmt % val) for key, val in lookup.items()]) lightbar.update([(key, fmt % val) for key, val in lookup.items()]) lightbar.colors['border'] = term.yellow echo(lightbar.border()) echo( lightbar.title(u''.join(( term.yellow(u'-'), term.bold_white(u'[ '), term.bold_yellow('CitY'), term.bold_white(u', '), term.bold_yellow('StAtE'), term.bold_white(u' ]'), term.yellow(u'-'), )))) echo( lightbar.footer(u''.join(( term.yellow(u'-'), term.bold_black(u'( '), term.yellow_underline('Escape'), u':', term.yellow('EXit'), term.bold_black(u' )'), term.yellow(u'-'), )))) lightbar.colors['highlight'] = term.yellow_reverse choice = lightbar.read() echo(lightbar.erase()) return ((loc for loc in locations if choice == loc['postal']).next() if choice is not None else choice)
def chose_location_lightbar(locations): """ Lightbar pager for chosing a location. """ from x84.bbs import getterminal, echo, Lightbar term = getterminal() fmt = u'%(city)s, %(state)s' lookup = dict([(loc['postal'], loc) for loc in locations]) fullheight = min(term.height - 8, len(locations) + 2) fullwidth = min(75, int(term.width * .8)) # shrink window to minimum width maxwidth = max([len(fmt % val) for val in lookup.values()]) + 2 if maxwidth < fullwidth: fullwidth = maxwidth echo(u'\r\n' * fullheight) lightbar = Lightbar(height=fullheight, width=fullwidth, yloc=term.height - fullheight, xloc=int((term.width / 2) - (fullwidth / 2))) lightbar.update([(key, fmt % val) for key, val in lookup.items()]) lightbar.update([(key, fmt % val) for key, val in lookup.items()]) lightbar.colors['border'] = term.yellow echo(lightbar.border()) echo(lightbar.title(u''.join(( term.yellow(u'-'), term.bold_white(u'[ '), term.bold_yellow('CitY'), term.bold_white(u', '), term.bold_yellow('StAtE'), term.bold_white(u' ]'), term.yellow(u'-'),)))) echo(lightbar.footer(u''.join(( term.yellow(u'-'), term.bold_black(u'( '), term.yellow_underline('Escape'), u':', term.yellow('EXit'), term.bold_black(u' )'), term.yellow(u'-'),)))) lightbar.colors['highlight'] = term.yellow_reverse choice = lightbar.read() echo(lightbar.erase()) return ((loc for loc in locations if choice == loc['postal'] ).next() if choice is not None else choice)
def main(ttyfile=u'', peek=False): """ Main procedure. """ # pylint: disable=R0914,R0915 # Too many local variables # Too many statements from x84.bbs import getsession, getterminal, echo, getch from x84.bbs import Door, ini, Lightbar import os import re ttyplay_exe = ini.CFG.get('ttyplay', 'exe') if not os.path.exists(ttyplay_exe): echo(u'\r\n%s NOt iNStAllEd.\r\n' % (ttyplay_exe,)) getch() return session, term = getsession(), getterminal() if 'sysop' in session.user.groups and ttyfile == u'': # pylint: disable=W0212 # Access to a protected member _ttyrec_folder of a client class folder = os.path.dirname(ttyfile) or session._ttyrec_folder files = sorted([fn for fn in os.listdir(session._ttyrec_folder) if fn.endswith('.ttyrec')]) echo(u'\r\n' * term.height) sel = Lightbar(term.height - 1, term.width - 1, 0, 0) sel.colors['border'] = term.bold_green echo(sel.border() + sel.title('- SElECt A RECORdiNG -')) sel.update([(fname, fname) for fname in files]) x_ttyfile = sel.read() if x_ttyfile is None or sel.quit: return ttyfile = os.path.join(folder, x_ttyfile) if not (os.path.exists(ttyfile) and os.path.isfile(ttyfile)): echo(term.bold_red('\r\n\r\nPAth NOt fOUNd: %s\r\n' % (ttyfile,))) getch() return # .. we could look for and write various information headers.. # .. esp. at EOF, about session.user.handle & connect_time & etc. data = open(ttyfile, 'rb').read(64) size_pattern = re.compile(r'\[8;(\d+);(\d+)t') match = size_pattern.match(data) if match: echo(u'\r\n\r\nheight, width: %s, %s' % match.groups()) args = tuple() if peek: args += ('-p',) elif 'sysop' in session.user.groups: echo("\r\nPRESS '%s' tO PEEk (2)\b\b" % ( (term.green_underline(u'p'),))) if getch(2) in (u'p', u'P'): peek = True args += (ttyfile,) door = Door(ttyplay_exe, args=args) session.activity = u'playing tty recording' # pylint: disable=W0212 # Access to a protected member _record_tty of a client class resume_rec = session._record_tty and session.is_recording if resume_rec: session.stop_recording() session._record_tty = False # press any key prompt, instructions for quitting (^c) .. echo(u'\r\n\r\n lOAd CASSEttE ANd PRESS %s. PRESS %s tO %s.\r\n' % ( term.green_reverse(u'PlAY'), term.green_underline('bREAk'), term.red_reverse(u'StOP'),)) getch() with term.fullscreen(): door.run() echo(u'\r\n\r\n') echo(u'PRESS ' + term.green_underline('q') + u'.') while not getch() in (u'q', u'Q'): pass if not session.is_recording and resume_rec: session._record_tty = True session.start_recording() echo(term.move(term.height, 0)) echo(u'\r\n')