<s> """<STR_LIT>""" <EOL> from __future__ import division <EOL> import collections <EOL> import os <EOL> from x84 . bbs import ( <EOL> syncterm_setfont , <EOL> getterminal , <EOL> getsession , <EOL> LineEditor , <EOL> get_ini , <EOL> gosub , <EOL> echo , <EOL> ini , <EOL> ) <EOL> from common import ( <EOL> render_menu_entries , <EOL> display_banner , <EOL> display_prompt , <EOL> ) <EOL> MenuItem = collections . namedtuple ( <EOL> '<STR_LIT>' , [ '<STR_LIT>' , '<STR_LIT:text>' , '<STR_LIT>' , '<STR_LIT:args>' , '<STR_LIT>' ] ) <EOL> colored_menu_items = get_ini ( <EOL> section = '<STR_LIT>' , key = '<STR_LIT>' , getter = '<STR_LIT>' <EOL> ) or True <EOL> color_highlight = get_ini ( <EOL> section = '<STR_LIT>' , key = '<STR_LIT>' <EOL> ) or '<STR_LIT>' <EOL> color_backlight = get_ini ( <EOL> section = '<STR_LIT>' , key = '<STR_LIT>' , <EOL> ) or '<STR_LIT>' <EOL> color_lowlight = get_ini ( <EOL> section = '<STR_LIT>' , key = '<STR_LIT>' <EOL> ) or '<STR_LIT>' <EOL> art_file = get_ini ( <EOL> section = '<STR_LIT>' , key = '<STR_LIT>' <EOL> ) or '<STR_LIT>' <EOL> art_encoding = get_ini ( <EOL> section = '<STR_LIT>' , key = '<STR_LIT>' <EOL> ) or '<STR_LIT>' <EOL> syncterm_font = get_ini ( <EOL> section = '<STR_LIT>' , key = '<STR_LIT>' <EOL> ) or '<STR_LIT>' <EOL> def get_sesame_menu_items ( session ) : <EOL> menu_items = [ ] <EOL> if ini . CFG . has_section ( '<STR_LIT>' ) : <EOL> for name in filter ( lambda _name : '<STR_LIT:_>' not in _name , <EOL> ini . CFG . options ( '<STR_LIT>' ) ) : <EOL> sesame_kwargs = { '<STR_LIT:name>' : name } <EOL> door_cmd = ini . CFG . get ( '<STR_LIT>' , name ) . split ( None , <NUM_LIT:1> ) [ <NUM_LIT:0> ] <EOL> if door_cmd . lower ( ) == '<STR_LIT>' or not os . path . exists ( door_cmd ) : <EOL> continue <EOL> inp_key = get_ini ( section = '<STR_LIT>' , key = '<STR_LIT>' . format ( name ) ) <EOL> if not inp_key : <EOL> raise ValueError ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' . format ( name ) ) <EOL> if get_ini ( section = '<STR_LIT>' , key = '<STR_LIT>' . format ( name ) , <EOL> getter = '<STR_LIT>' ) and not session . user . is_sysop : <EOL> continue <EOL> text = get_ini ( <EOL> section = '<STR_LIT>' , key = '<STR_LIT>' . format ( name ) <EOL> ) or name <EOL> menu_items . append ( <EOL> MenuItem ( inp_key = inp_key , text = text , script = '<STR_LIT>' , <EOL> args = ( ) , kwargs = sesame_kwargs ) ) <EOL> return menu_items <EOL> def get_menu_items ( session ) : <EOL> """<STR_LIT>""" <EOL> menu_items = [ <EOL> MenuItem ( inp_key = u'<STR_LIT>' , <EOL> text = u'<STR_LIT>' , <EOL> script = '<STR_LIT>' , <EOL> args = ( ) , kwargs = { } ) , <EOL> MenuItem ( inp_key = u'<STR_LIT>' , <EOL> text = u"<STR_LIT>" , <EOL> script = '<STR_LIT>' , <EOL> args = ( ) , kwargs = { } ) , <EOL> MenuItem ( inp_key = u'<STR_LIT>' , <EOL> text = u'<STR_LIT>' , <EOL> script = '<STR_LIT>' , <EOL> args = ( ) , kwargs = { } ) , <EOL> MenuItem ( inp_key = u'<STR_LIT>' , <EOL> text = u'<STR_LIT>' , <EOL> script = '<STR_LIT>' , <EOL> args = ( ) , kwargs = { } ) , <EOL> MenuItem ( inp_key = u'<STR_LIT>' , <EOL> text = u'<STR_LIT>' , <EOL> script = '<STR_LIT>' , <EOL> args = ( ) , kwargs = { } ) , <EOL> MenuItem ( inp_key = u'<STR_LIT>' , <EOL> text = u'<STR_LIT>' , <EOL> script = '<STR_LIT>' , <EOL> args = ( ) , kwargs = { } ) , <EOL> MenuItem ( inp_key = u'<STR_LIT>' , <EOL> text = u'<STR_LIT>' , <EOL> script = '<STR_LIT>' , <EOL> args = ( ) , kwargs = { } ) , <EOL> MenuItem ( inp_key = u'<STR_LIT>' , <EOL> text = u'<STR_LIT>' , <EOL> script = '<STR_LIT>' , <EOL> args = ( ) , kwargs = { } ) , <EOL> MenuItem ( inp_key = u'<STR_LIT>' , <EOL> text = u'<STR_LIT>' , <EOL> script = '<STR_LIT>' , <EOL> args = ( ) , kwargs = { } ) , <EOL> MenuItem ( inp_key = u'<STR_LIT>' , <EOL> text = u'<STR_LIT>' , <EOL> script = '<STR_LIT>' , <EOL> args = ( ) , kwargs = { } ) , <EOL> MenuItem ( inp_key = u'<STR_LIT:user>' , <EOL> text = u'<STR_LIT>' , <EOL> script = '<STR_LIT>' , <EOL> args = ( ) , kwargs = { } ) , <EOL> MenuItem ( inp_key = u'<STR_LIT>' , <EOL> text = u'<STR_LIT>' , <EOL> script = '<STR_LIT>' , <EOL> args = ( ) , kwargs = { } ) , <EOL> MenuItem ( inp_key = u'<STR_LIT>' , <EOL> text = u'<STR_LIT>' , <EOL> script = '<STR_LIT>' , <EOL> args = ( ) , kwargs = { } ) , <EOL> MenuItem ( inp_key = u'<STR_LIT:key>' , <EOL> text = u'<STR_LIT>' , <EOL> script = '<STR_LIT>' , <EOL> args = ( ) , kwargs = { } ) , <EOL> MenuItem ( inp_key = u'<STR_LIT>' , <EOL> text = u'<STR_LIT>' , <EOL> script = '<STR_LIT>' , <EOL> args = ( ) , kwargs = { } ) , <EOL> MenuItem ( inp_key = u'<STR_LIT>' , <EOL> text = u'<STR_LIT>' , <EOL> script = '<STR_LIT>' , <EOL> args = ( ) , kwargs = { } ) , <EOL> MenuItem ( inp_key = u'<STR_LIT:g>' , <EOL> text = u'<STR_LIT>' , <EOL> script = '<STR_LIT>' , <EOL> args = ( ) , kwargs = { } ) , <EOL> ] <EOL> if session . user . is_sysop : <EOL> menu_items . append ( <EOL> MenuItem ( inp_key = '<STR_LIT>' , <EOL> text = u'<STR_LIT>' , <EOL> script = '<STR_LIT>' , <EOL> args = ( ) , kwargs = { } ) ) <EOL> menu_items . extend ( get_sesame_menu_items ( session ) ) <EOL> return menu_items <EOL> def get_line_editor ( term , menu ) : <EOL> """<STR_LIT>""" <EOL> max_inp_length = max ( [ len ( item . inp_key ) for item in menu ] ) <EOL> return LineEditor ( width = max_inp_length , <EOL> colors = { '<STR_LIT>' : getattr ( term , color_backlight ) } ) <EOL> def main ( ) : <EOL> """<STR_LIT>""" <EOL> session , term = getsession ( ) , getterminal ( ) <EOL> text , width , height , dirty = u'<STR_LIT>' , - <NUM_LIT:1> , - <NUM_LIT:1> , <NUM_LIT:2> <EOL> menu_items = get_menu_items ( session ) <EOL> editor = get_line_editor ( term , menu_items ) <EOL> colors = { } <EOL> if colored_menu_items : <EOL> colors [ '<STR_LIT>' ] = getattr ( term , color_backlight ) <EOL> colors [ '<STR_LIT>' ] = getattr ( term , color_highlight ) <EOL> colors [ '<STR_LIT>' ] = getattr ( term , color_lowlight ) <EOL> while True : <EOL> if dirty == <NUM_LIT:2> : <EOL> if syncterm_font and term . kind . startswith ( '<STR_LIT>' ) : <EOL> echo ( syncterm_setfont ( syncterm_font ) ) <EOL> if dirty : <EOL> session . activity = '<STR_LIT>' <EOL> top_margin = display_banner ( art_file , encoding = art_encoding ) + <NUM_LIT:1> <EOL> echo ( u'<STR_LIT:\r\n>' ) <EOL> if width != term . width or height != term . height : <EOL> width , height = term . width , term . height <EOL> text = render_menu_entries ( <EOL> term , top_margin , menu_items , colors ) <EOL> echo ( u'<STR_LIT>' . join ( ( text , <EOL> display_prompt ( term , colors ) , <EOL> editor . refresh ( ) ) ) ) <EOL> dirty = <NUM_LIT:0> <EOL> event , data = session . read_events ( ( '<STR_LIT:input>' , '<STR_LIT>' ) ) <EOL> if event == '<STR_LIT>' : <EOL> dirty = True <EOL> continue <EOL> elif event == '<STR_LIT:input>' : <EOL> session . buffer_input ( data , pushback = True ) <EOL> inp = term . inkey ( <NUM_LIT:0> ) <EOL> while inp : <EOL> if inp . code == term . KEY_ENTER : <EOL> for item in menu_items : <EOL> if item . inp_key == editor . content . strip ( ) : <EOL> echo ( term . normal + u'<STR_LIT:\r\n>' ) <EOL> gosub ( item . script , * item . args , ** item . kwargs ) <EOL> editor . content = u'<STR_LIT>' <EOL> dirty = <NUM_LIT:2> <EOL> break <EOL> else : <EOL> if editor . content : <EOL> echo ( u'<STR_LIT>' . join ( ( <EOL> ( u'<STR_LIT>' * len ( editor . content ) ) , <EOL> ( u'<STR_LIT:U+0020>' * len ( editor . content ) ) , <EOL> ( u'<STR_LIT>' * len ( editor . content ) ) , ) ) ) <EOL> editor . content = u'<STR_LIT>' <EOL> echo ( editor . refresh ( ) ) <EOL> elif inp . is_sequence : <EOL> echo ( editor . process_keystroke ( inp . code ) ) <EOL> else : <EOL> echo ( editor . process_keystroke ( inp ) ) <EOL> inp = term . inkey ( <NUM_LIT:0> ) </s>
