def get_ui(position=None): """ Returns user interface (lightbar, pager). Optional argument position is tuple position of prior lightbar instance. """ from x84.bbs import getterminal, Lightbar, Pager term = getterminal() assert term.height > 10 and term.width >= 40 # +-+ +----+ # |lb |pager # +-+ +----+ height = term.height - 7 lb_width = int(term.width * .3) pg_width = term.width - (lb_width) lb_xloc = (term.width / 2) - (term.width / 2) pg_xloc = lb_xloc + lb_width lightbar = Lightbar(height, lb_width, (term.height - height - 1), lb_xloc) pager = Pager(height, pg_width, (term.height - height - 1), pg_xloc) pager.ypadding = 2 pager.xpadding = 2 lightbar.update(get_bbslist(max_len=lightbar.visible_width)) ## pressing Return is same as 't'elnet lightbar.keyset['enter'].extend((u't', u'T')) ## re-select previous selection if position is not None: lightbar.position = position return (pager, lightbar)
def get_ui(position=None): """ Returns user interface (lightbar, pager). Optional argument position is tuple position of prior lightbar instance. """ from x84.bbs import getterminal, Lightbar, Pager term = getterminal() assert term.height > 10 and term.width >= 40 # +-+ +----+ # |lb |pager # +-+ +----+ height = term.height - 7 lb_width = int(term.width * .3) pg_width = term.width - (lb_width) lb_xloc = (term.width / 2) - (term.width / 2) pg_xloc = lb_xloc + lb_width lightbar = Lightbar(height, lb_width, (term.height - height - 1), lb_xloc) pager = Pager(height, pg_width, (term.height - height - 1), pg_xloc) pager.ypadding = 2 pager.xpadding = 2 lightbar.update(get_bbslist(max_len=lightbar.visible_width)) ## pressing Return is same as 't'elnet lightbar.keyset['enter'].extend((u't', u'T')) ## re-select previous selection if position is not None: lightbar.position = position return (pager, lightbar)
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 get_selector(mailbox, prev_sel=None): """ Provide Lightbar UI element given message mailbox returned from function get_header, and prev_sel as previously instantiated Lightbar. """ from x84.bbs import Lightbar pos = prev_sel.position if prev_sel is not None else (0, 0) sel = Lightbar( height=(term.height / 3 if term.width < 140 else term.height - 3), width=len_preview, yloc=2, xloc=0) sel.glyphs['top-horiz'] = u'' sel.glyphs['left-vert'] = u'' sel.colors['highlight'] = term.yellow_reverse sel.update(mailbox) sel.position = pos return sel
def lb_init(position=None, menu_index=None): """ Initialize Lightbar Main Menu """ from x84.bbs import getsession, getterminal, echo, showart, ini, Lightbar import os import logging logger = logging.getLogger() session, term = getsession(), getterminal() session.activity = u'Lightbar main menu' # set up lightbar pager, determine terminal dimensions term = getterminal() height = term.height - 11 lb_width = int(term.width * .4) lb_xloc = int(term.width * .3) lightbar = Lightbar(height, lb_width, (term.height - height - 1), lb_xloc) # Lightbar main menu entries entries = [ #('', '-----[COmMs]-----'), ('$', 'rEAD bUllETiNS'), ('n', 'latest nEWS'), ('p', 'pOSt A MSG'), ('r', 'rEAd All MSGS'), ('c', 'chAt'), ('i', 'iRC chAt'), #('', ' '), #('', '----[SeRVIcES]----'), ('l', 'lASt CAllS'), ('o', 'oNE liNERS'), ('b', 'bbS NEXUS'), ('f', 'WeAThER fORECASt'), ('t', 'tEtRiS'), ('w', "whO'S ONliNE"), #('', ' '), #('', '-----[SySTeM]-----'), ('!', 'ENCOdiNG'), ('s', 'sYS. iNfO'), ('u', 'uSER LiST'), ('e', 'edit PROfilE'), ] 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))) if 'sysop' in session.user.groups: entries += (('v', 'VidEO CASSEttE'), ) entries += (('g', 'gOOdbYE /lOGOff'), ) lightbar.update(entries) if menu_index is not None: lightbar.goto(menu_index) # set up some nice colors lightbar.colors['highlight'] = term.bold_cyan_reverse lightbar.colors['border'] = term.bold_blue lightbar.xpadding, lightbar.ypadding = 2, 1 lightbar.alignment = 'center' # set lightbar theme #lightbar.init_theme() ## re-select previous selection if position is not None: lightbar.position = position return (lightbar)
def lb_init(position=None, menu_index=None): """ Initialize Lightbar Main Menu """ from x84.bbs import getsession, getterminal, ini, Lightbar import os import logging logger = logging.getLogger() session, term = getsession(), getterminal() session.activity = u'Lightbar main menu' # set up lightbar pager, determine terminal dimensions term = getterminal() height = term.height - 11 lb_width = int(term.width * .4) lb_xloc = int(term.width * .3) lightbar = Lightbar(height, lb_width, (term.height - height - 1), lb_xloc) # Lightbar main menu entries entries = [ ('', '-----[COmMs]-----'), ('$', 'rEAD bUllETiNS'), ('n', 'latest nEWS'), ('hn', 'hACkEr nEWS'), # ('p', 'pOSt A MSG'), ('r', 'MEsSAgE ArEAs'), ('c', 'chAt'), ('i', 'iRC chAt'), ('', ' '), ('', '----[FIleS]----'), ('fb', 'FIle BrOWsEr'), ('', ' '), ('', '----[SeRVIcES]----'), ('l', 'lASt CAllS'), ('o', 'oNE liNERS'), ('b', 'bbS NEXUS'), ('f', 'WeAThER fORECASt'), ('t', 'tEtRiS'), ('v', "vOtINg BoOth"), ('w', "whO'S ONliNE"), ('', ' '), ('', '-----[SySTeM]-----'), ('!', 'ENCOdiNG'), ('kb', 'kEYbOaRd tESt'), ('s', 'sYS. iNfO'), ('u', 'uSER LiST'), ('e', 'edit PROfilE'), ] 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))) if 'sysop' in session.user.groups: entries += (('v', 'VidEO CASSEttE'),) entries += (('g', 'gOOdbYE /lOGOff'),) lightbar.update(entries) if menu_index is not None: lightbar.goto(menu_index) # set up some nice colors lightbar.colors['highlight'] = term.bold_cyan_reverse lightbar.colors['border'] = term.bold_blue lightbar.xpadding, lightbar.ypadding = 2, 1 lightbar.alignment = 'center' # set lightbar theme # lightbar.init_theme() # re-select previous selection if position is not None: lightbar.position = position return (lightbar)