<s> from __future__ import unicode_literals , division , absolute_import , print_function <EOL> import glob <EOL> import os <EOL> import readline <EOL> import six <EOL> def path_complete ( text , state ) : <EOL> if '<STR_LIT>' in text : <EOL> if text == '<STR_LIT>' : <EOL> text += '<STR_LIT:/>' <EOL> text = os . path . expanduser ( text ) <EOL> return ( glob . glob ( text + '<STR_LIT:*>' ) + [ None ] ) [ state ] <EOL> readline . set_completer_delims ( '<STR_LIT>' ) <EOL> readline . parse_and_bind ( "<STR_LIT>" ) <EOL> readline . set_completer ( path_complete ) <EOL> class Color ( object ) : <EOL> CLEAR = - <NUM_LIT:1> <EOL> LIGHT = <NUM_LIT:1> <EOL> UNDERLINE = <NUM_LIT:4> <EOL> BLINK = <NUM_LIT:5> <EOL> SWAP = <NUM_LIT:7> <EOL> HIDE = <NUM_LIT:8> <EOL> FOREGROUND = <NUM_LIT:30> <EOL> BACKGROUND = <NUM_LIT> <EOL> BLACK = <NUM_LIT:0> <EOL> RED = <NUM_LIT:1> <EOL> GREEN = <NUM_LIT:2> <EOL> YELLOW = <NUM_LIT:3> <EOL> BLUE = <NUM_LIT:4> <EOL> MAGENTA = <NUM_LIT:5> <EOL> CYAN = <NUM_LIT:6> <EOL> WHITE = <NUM_LIT:7> <EOL> LIGHT_BLACK = <NUM_LIT> <EOL> LIGHT_RED = <NUM_LIT> <EOL> LIGHT_GREEN = <NUM_LIT> <EOL> LIGHT_YELLOW = <NUM_LIT> <EOL> LIGHT_BLUE = <NUM_LIT:64> <EOL> LIGHT_MAGENTA = <NUM_LIT> <EOL> LIGHT_CYAN = <NUM_LIT> <EOL> LIGHT_WHITE = <NUM_LIT> <EOL> @ classmethod <EOL> def str ( cls , message , foreground = - <NUM_LIT:1> , background = - <NUM_LIT:1> , <EOL> light = False , underline = False , blink = False , swap = False , hide = False ) : <EOL> codes = [ ] <EOL> if light : <EOL> codes . append ( cls . LIGHT ) <EOL> if underline : <EOL> codes . append ( cls . UNDERLINE ) <EOL> if blink : <EOL> codes . append ( cls . BLINK ) <EOL> if swap : <EOL> codes . append ( cls . SWAP ) <EOL> if hide : <EOL> codes . append ( cls . HIDE ) <EOL> if foreground >= <NUM_LIT:0> : <EOL> codes . append ( cls . FOREGROUND + foreground ) <EOL> if background >= <NUM_LIT:0> : <EOL> codes . append ( cls . BACKGROUND + background ) <EOL> return cls . str_with_codes ( message , * codes ) <EOL> @ classmethod <EOL> def str_with_codes ( cls , message , * codes ) : <EOL> return '<STR_LIT>' . format ( cls . code ( * codes ) , message , cls . code ( ) ) <EOL> @ classmethod <EOL> def code ( cls , * codes ) : <EOL> return '<STR_LIT>' . format ( '<STR_LIT:;>' . join ( map ( str , codes ) ) ) <EOL> class Console ( object ) : <EOL> error_prefix = '<STR_LIT>' <EOL> error_color = ( Color . RED , False ) <EOL> success_prefix = '<STR_LIT>' <EOL> success_color = ( Color . GREEN , False ) <EOL> info_prefix = '<STR_LIT>' <EOL> info_color = ( Color . CYAN , False ) <EOL> prompt_prefix = '<STR_LIT>' <EOL> prompt_color = ( Color . MAGENTA , False ) <EOL> highlight_prefix = '<STR_LIT>' <EOL> highlight_color = ( Color . CYAN , True ) <EOL> warn_prefix = '<STR_LIT>' <EOL> warn_color = ( Color . YELLOW , False ) <EOL> def __init__ ( self , f , write_line = True , color = True ) : <EOL> self . output_color = color <EOL> self . _output = f <EOL> self . _write_line = write_line <EOL> def __getattr__ ( self , name ) : <EOL> if name . endswith ( '<STR_LIT>' ) or name . endswith ( '<STR_LIT>' ) : <EOL> raise AttributeError ( "<STR_LIT>" . format ( self . __class__ . __name__ , name ) ) <EOL> color , light = getattr ( self , '<STR_LIT>' . format ( name ) , ( Color . CLEAR , False ) ) <EOL> prefix = getattr ( self , '<STR_LIT>' . format ( name ) , '<STR_LIT>' ) <EOL> def func ( message , bar_width = <NUM_LIT:0> , bar_character = '<STR_LIT:=>' ) : <EOL> self . show ( '<STR_LIT>' . format ( prefix , message ) , <EOL> foreground = color , light = light , bar_width = bar_width , bar_character = bar_character ) <EOL> return func <EOL> def show ( self , message , foreground = - <NUM_LIT:1> , background = - <NUM_LIT:1> , light = False , bar_width = <NUM_LIT:0> , bar_character = '<STR_LIT:=>' ) : <EOL> if bar_width != <NUM_LIT:0> : <EOL> message = self . bar ( message , bar_width , bar_character ) <EOL> output_str = Color . str ( message , foreground , background , light ) if self . output_color else message <EOL> if self . _write_line : <EOL> output_str += '<STR_LIT:\n>' <EOL> self . _output . write ( output_str ) <EOL> @ staticmethod <EOL> def bar ( message , width = <NUM_LIT> , character = '<STR_LIT:=>' ) : <EOL> if message : <EOL> message += '<STR_LIT:U+0020>' <EOL> return message + character * ( width - ( len ( message ) + <NUM_LIT:1> ) ) <EOL> def input ( self , prompt , <EOL> hint = None , validators = None , repeat_until_valid = False , task = None , leave_when_cancel = None , ** kwargs ) : <EOL> has_default = '<STR_LIT:default>' in kwargs <EOL> default = kwargs . get ( '<STR_LIT:default>' , None ) <EOL> leave_when_cancel = leave_when_cancel or bool ( task ) <EOL> message_components = [ prompt , '<STR_LIT:U+0020>' ] <EOL> if hint is not None : <EOL> message_components . append ( '<STR_LIT>' . format ( hint ) ) <EOL> if has_default : <EOL> message_components . append ( '<STR_LIT>' . format ( default ) ) <EOL> message = '<STR_LIT>' . join ( message_components ) . strip ( ) + '<STR_LIT>' <EOL> while True : <EOL> has_result = True <EOL> try : <EOL> result = six . moves . input ( message ) . strip ( ) <EOL> except KeyboardInterrupt : <EOL> self . show ( '<STR_LIT>' ) <EOL> error_msg = '<STR_LIT>' <EOL> self . error ( error_msg ) <EOL> if task and leave_when_cancel : <EOL> task . exit ( <NUM_LIT:1> ) <EOL> else : <EOL> if ( result is None or len ( result ) == <NUM_LIT:0> ) and has_default : <EOL> result = default <EOL> if validators : <EOL> for validator in validators : <EOL> try : <EOL> result = validator ( result ) <EOL> except Exception as e : <EOL> has_result = False <EOL> if has_default : <EOL> result = validator ( default ) <EOL> else : <EOL> self . error ( str ( e ) ) <EOL> break <EOL> if not repeat_until_valid or has_result : <EOL> return result </s>
