<s> from sublime import Region , Window <EOL> from . _view import ViewSettings , unset_read_only , append , clear , get_text <EOL> from . . import ST3 <EOL> if ST3 : <EOL> basestring = str <EOL> class OutputPanel ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , window , panel_name , file_regex = None , <EOL> line_regex = None , path = None , read_only = True , <EOL> auto_show = True ) : <EOL> if not isinstance ( window , Window ) : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> if not isinstance ( panel_name , basestring ) : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> self . window = window <EOL> self . panel_name = panel_name <EOL> self . view = window . get_output_panel ( panel_name ) <EOL> self . view . set_read_only ( read_only ) <EOL> self . settings = ViewSettings ( self . view ) <EOL> self . set_path ( path , file_regex , line_regex ) <EOL> self . auto_show = auto_show <EOL> def set_path ( self , path = None , file_regex = None , line_regex = None ) : <EOL> """<STR_LIT>""" <EOL> if path is not None : <EOL> self . settings . result_base_dir = path <EOL> self . set_regex ( file_regex , line_regex ) <EOL> def set_regex ( self , file_regex = None , line_regex = None ) : <EOL> """<STR_LIT>""" <EOL> if file_regex is not None : <EOL> self . file_regex = file_regex <EOL> if hasattr ( self , '<STR_LIT>' ) : <EOL> self . settings . result_file_regex = self . file_regex <EOL> if line_regex is not None : <EOL> self . line_regex = line_regex <EOL> if hasattr ( self , '<STR_LIT>' ) : <EOL> self . settings . result_line_regex = self . line_regex <EOL> contents = get_text ( self . view ) <EOL> sel = self . view . sel ( ) <EOL> selections = list ( sel ) <EOL> self . view = self . window . get_output_panel ( self . panel_name ) <EOL> sel . clear ( ) <EOL> for reg in selections : <EOL> sel . add ( reg ) <EOL> self . write ( contents ) <EOL> def write ( self , text ) : <EOL> """<STR_LIT>""" <EOL> with unset_read_only ( self . view ) : <EOL> append ( self . view , text ) <EOL> def write_line ( self , text = '<STR_LIT>' ) : <EOL> """<STR_LIT>""" <EOL> self . write ( text + "<STR_LIT:\n>" ) <EOL> def clear ( self ) : <EOL> """<STR_LIT>""" <EOL> with unset_read_only ( self . view ) : <EOL> clear ( self . view ) <EOL> def show ( self ) : <EOL> """<STR_LIT>""" <EOL> self . window . run_command ( "<STR_LIT>" , <EOL> { "<STR_LIT>" : "<STR_LIT>" % self . panel_name } ) <EOL> def hide ( self ) : <EOL> """<STR_LIT>""" <EOL> self . window . run_command ( "<STR_LIT>" , <EOL> { "<STR_LIT>" : "<STR_LIT>" % self . panel_name } ) <EOL> def finish ( self ) : <EOL> """<STR_LIT>""" <EOL> self . set_path ( ) <EOL> self . view . sel ( ) . clear ( ) <EOL> self . view . sel ( ) . add ( Region ( <NUM_LIT:0> ) ) <EOL> if self . auto_show : <EOL> if self . view . size ( ) : <EOL> self . show ( ) <EOL> else : <EOL> self . hide ( ) <EOL> def __enter__ ( self ) : <EOL> return self <EOL> def __exit__ ( self , type , value , traceback ) : <EOL> self . finish ( ) </s>
