<s> import os <EOL> import sublime <EOL> import sublime_plugin <EOL> import sys <EOL> BASE_PATH = os . path . abspath ( os . path . dirname ( __file__ ) ) <EOL> sys . path . append ( BASE_PATH ) <EOL> def figlet_text ( text ) : <EOL> import pyfiglet <EOL> settings = sublime . load_settings ( "<STR_LIT>" ) <EOL> font = settings . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> width = get_width ( ) <EOL> result = pyfiglet . Figlet ( font = font , width = width ) . renderText ( text = text ) <EOL> if settings . get ( '<STR_LIT>' , True ) : <EOL> result = '<STR_LIT:\n>' . join ( ( line . rstrip ( ) for line in result . split ( '<STR_LIT:\n>' ) ) ) <EOL> return result [ : len ( result ) - <NUM_LIT:1> ] <EOL> def get_width ( ) : <EOL> width = <NUM_LIT> <EOL> view_settings = sublime . active_window ( ) . active_view ( ) . settings ( ) <EOL> if view_settings . get ( '<STR_LIT>' ) : <EOL> output_width = view_settings . get ( '<STR_LIT>' ) <EOL> if output_width not in ( None , <NUM_LIT:0> ) : <EOL> width = output_width <EOL> return width <EOL> class FigletSelectFontCommand ( sublime_plugin . WindowCommand ) : <EOL> def run ( self ) : <EOL> import pyfiglet <EOL> self . fonts = pyfiglet . FigletFont . getFonts ( ) <EOL> self . window . show_quick_panel ( self . fonts , self . on_done ) <EOL> def on_done ( self , index ) : <EOL> settings = sublime . load_settings ( "<STR_LIT>" ) <EOL> settings . set ( "<STR_LIT>" , self . fonts [ index ] ) <EOL> sublime . save_settings ( "<STR_LIT>" ) <EOL> class FigletTextCommand ( sublime_plugin . WindowCommand ) : <EOL> def run ( self ) : <EOL> view = self . window . active_view ( ) <EOL> sel = view . sel ( ) <EOL> if len ( sel ) == <NUM_LIT:1> and sel [ <NUM_LIT:0> ] . size ( ) > <NUM_LIT:0> : <EOL> view . run_command ( '<STR_LIT>' , { '<STR_LIT:text>' : None } ) <EOL> else : <EOL> self . window . show_input_panel ( "<STR_LIT>" , "<STR_LIT>" , <EOL> self . on_done , None , None ) <EOL> def on_done ( self , text ) : <EOL> view = self . window . active_view ( ) <EOL> view . run_command ( '<STR_LIT>' , { '<STR_LIT:text>' : text } ) <EOL> class FigletInsertTextCommand ( sublime_plugin . TextCommand ) : <EOL> def run ( self , edit , text = None ) : <EOL> view = self . view <EOL> sel = view . sel ( ) <EOL> if text is None : <EOL> if len ( sel ) != <NUM_LIT:1> or sel [ <NUM_LIT:0> ] . size ( ) == <NUM_LIT:0> : <EOL> return <EOL> text = view . substr ( sel [ <NUM_LIT:0> ] ) <EOL> cursor = min ( sel [ <NUM_LIT:0> ] . a , sel [ <NUM_LIT:0> ] . b ) <EOL> text = figlet_text ( text ) <EOL> view . erase ( edit , sel [ <NUM_LIT:0> ] ) <EOL> view . insert ( edit , cursor , text ) <EOL> sel . clear ( ) <EOL> sel . add ( sublime . Region ( cursor , cursor + len ( text ) ) ) </s>
