def run( self, edit ):
        self.undo = False
        settings = sublime.load_settings('ASCII Decorator.sublime-settings')

        # Find directory locations
        font_locations = figlet_paths()

        # Find available fonts
        self.options = []
        for fl in font_locations:
            for f in os.listdir(fl):
                pth = os.path.join(fl, f)
                if os.path.isfile(pth):
                    if f.endswith((".flf", ".tlf")):
                        self.options.append(f)

        self.options.sort()

        # Prepare and show quick panel
        if len(self.options):
            if not ST3:
                self.view.window().show_quick_panel(
                    [o[:-4] for o in self.options],
                    self.apply_figlet
                )
            else:
                self.view.window().show_quick_panel(
                    [o[:-4] for o in self.options],
                    self.apply_figlet,
                    on_highlight=self.preview if bool(settings.get("show_preview", False)) else None
                )
    def run(self, edit):
        self.undo = False
        settings = sublime.load_settings('ASCII Decorator.sublime-settings')

        # Find directory locations
        font_locations = figlet_paths()

        # Find available fonts
        self.options = []
        for fl in font_locations:
            for f in os.listdir(fl):
                pth = os.path.join(fl, f)
                if os.path.isfile(pth):
                    if f.endswith((".flf", ".tlf")):
                        self.options.append(f)

        self.options.sort()

        # Prepare and show quick panel
        if len(self.options):
            if not ST3:
                self.view.window().show_quick_panel(
                    [o[:-4] for o in self.options], self.apply_figlet)
            else:
                self.view.window().show_quick_panel(
                    [o[:-4] for o in self.options],
                    self.apply_figlet,
                    on_highlight=self.preview if bool(
                        settings.get("show_preview", False)) else None)
    def run(self, text):
        # Find directory locations
        font_locations = figlet_paths()

        # Find available fonts
        self.options = []
        for fl in font_locations:
            for f in os.listdir(fl):
                pth = os.path.join(fl, f)
                if os.path.isfile(pth):
                    if f.endswith((".flf", ".tlf")):
                        self.options.append((f[:-4], fl))

        self.options.sort()

        with tempfile.NamedTemporaryFile(mode = 'wb', delete=False, suffix='.txt') as p:
            for font in self.options:
                f = SublimeFiglet(
                    font=font[0], directory=font[1], width=80,
                    justify="auto", direction="auto"
                )
                p.write(("Font: %s Directory: %s\n" % (font[0], font[1])).encode("utf-8"))
                p.write(f.renderText(text).replace('\r\n', '\n').replace('\r', '\n').encode('utf-8'))
                p.write("\n\n".encode("utf-8"))

        self.window.open_file(p.name)
    def run(self, text):
        # Find directory locations
        font_locations = figlet_paths()

        # Find available fonts
        self.options = []
        for fl in font_locations:
            for f in os.listdir(fl):
                pth = os.path.join(fl, f)
                if os.path.isfile(pth):
                    if f.endswith((".flf", ".tlf")):
                        self.options.append((f[:-4], fl))

        self.options.sort()

        with tempfile.NamedTemporaryFile(mode='wb',
                                         delete=False,
                                         suffix='.txt') as p:
            for font in self.options:
                f = SublimeFiglet(font=font[0],
                                  directory=font[1],
                                  width=80,
                                  justify="auto",
                                  direction="auto")
                p.write(("Font: %s Directory: %s\n" %
                         (font[0], font[1])).encode("utf-8"))
                p.write(
                    f.renderText(text).replace('\r\n', '\n').replace(
                        '\r', '\n').encode('utf-8'))
                p.write("\n\n".encode("utf-8"))

        self.window.open_file(p.name)
    def decorate_multi(self, edit, currentSelections):
        """
            Take input and use FIGlet to convert it to ASCII art.
            Normalize converted ASCII strings to use proper line endings and spaces/tabs.
        """

        # Convert the input range to a string, this represents the original selection.
        font_locations = figlet_paths() if self.directory is None else [
            self.directory
        ]

        # Find where the font resides
        directory = None
        found = False
        for fl in font_locations:
            pth = os.path.join(fl, self.font)
            for ext in (".flf", ".tlf"):
                directory = fl
                if os.path.exists(pth + ext):
                    found = True
                    break
            if found is True:
                break
        assert found is True

        output = []

        for line in currentSelections:
            original = self.view.substr(line)

            # Convert the input string to ASCII Art.
            f = SublimeFiglet(directory=directory,
                              font=self.font,
                              width=self.width,
                              justify=self.justify,
                              direction=self.direction)
            line_output = f.renderText(original)
            if self.reverse is True:
                line_output = line_output.reverse()
            if self.flip is True:
                line_output = line_output.flip()

            if not ST3:
                line_output = line_output.decode("utf-8", "replace")
            output.append(line_output)

        # Normalize line endings based on settings.
        output = self.normalize_line_endings('\n'.join(output))
        # Normalize whitespace based on settings.
        totalselection = sublime.Region(currentSelections[0].begin(),
                                        currentSelections[-1].end())
        output = self.fix_whitespace(original, output, totalselection)

        self.view.replace(edit, totalselection, output)

        return sublime.Region(totalselection.begin(),
                              totalselection.begin() + len(output))
    def run(self, text = "Lorem Ipsum", use_selected_text = False):
        # Find directory locations
        font_locations = figlet_paths()

        # Verify selected text
        if use_selected_text == True:

            view = self.window.active_view()
            selections = view.sel()
            regionCount = len( selections )

            if regionCount == 0 or regionCount > 1:
                return

            selection = selections[0]
            line_A = view.line( selection.a )
            line_B = view.line( selection.b )

            if line_A != line_B:
                return

            if selection.a == selection.b:
                sourceRegion = line_A
            else:
                sourceRegion = selection

            text = view.substr( sourceRegion )
            text = text.strip()

            if text == "":
                return

        # Find available fonts
        self.options = []
        for fl in font_locations:
            for f in os.listdir(fl):
                pth = os.path.join(fl, f)
                if os.path.isfile(pth):
                    if f.endswith((".flf", ".tlf")):
                        self.options.append((f[:-4], fl))

        self.options.sort()

        with tempfile.NamedTemporaryFile(mode = 'wb', delete=False, suffix='.txt') as p:
            for font in self.options:
                f = SublimeFiglet(
                    font=font[0], directory=font[1], width=80,
                    justify="auto", direction="auto"
                )
                p.write(("Font: %s Directory: %s\n" % (font[0], font[1])).encode("utf-8"))
                p.write(
                    remove_trailing_ws(f.renderText(text).replace('\r\n', '\n').replace('\r', '\n')).encode('utf-8')
                )
                p.write("\n\n".encode("utf-8"))

        self.window.open_file(p.name)
    def decorate_multi( self, edit, currentSelections ):
        """
            Take input and use FIGlet to convert it to ASCII art.
            Normalize converted ASCII strings to use proper line endings and spaces/tabs.
        """

        # Convert the input range to a string, this represents the original selection.
        font_locations = figlet_paths() if self.directory is None else [self.directory]

        # Find where the font resides
        directory = None
        found = False
        for fl in font_locations:
            pth = os.path.join(fl, self.font)
            for ext in (".flf", ".tlf"):
                directory = fl
                if os.path.exists(pth + ext):
                    found = True
                    break
            if found is True:
                break
        assert found is True

        output = []

        for line in currentSelections:
            original = self.view.substr(line)

            # Convert the input string to ASCII Art.
            f = SublimeFiglet(
                directory=directory, font=self.font, width=self.width,
                justify=self.justify, direction=self.direction
            )
            line_output = f.renderText( original )
            if self.reverse is True:
                line_output = line_output.reverse()
            if self.flip is True:
                line_output = line_output.flip()

            if not ST3:
                line_output = line_output.decode("utf-8", "replace")
            output.append(line_output)

        # Normalize line endings based on settings.
        output = self.normalize_line_endings( '\n'.join(output) )
        # Normalize whitespace based on settings.
        totalselection = sublime.Region(currentSelections[0].begin(), currentSelections[-1].end())
        output = self.fix_whitespace( original, output, totalselection )

        self.view.replace( edit, totalselection, output )

        return sublime.Region( totalselection.begin(), totalselection.begin() + len(output) )
    def run(self, text="Lorem Ipsum", use_selected_text=False):
        # Find directory locations
        font_locations = figlet_paths()

        # Verify selected text
        if use_selected_text == True:

            view = self.window.active_view()
            selections = view.sel()
            regionCount = len(selections)

            if regionCount == 0 or regionCount > 1:
                return

            selection = selections[0]
            line_A = view.line(selection.a)
            line_B = view.line(selection.b)

            if line_A != line_B:
                return

            if selection.a == selection.b:
                sourceRegion = line_A
            else:
                sourceRegion = selection

            text = view.substr(sourceRegion)
            text = text.strip()

            if text == "":
                return

        # Find available fonts
        self.options = []
        for fl in font_locations:
            for f in os.listdir(fl):
                pth = os.path.join(fl, f)
                if os.path.isfile(pth):
                    if f.endswith((".flf", ".tlf")):
                        self.options.append((f[:-4], fl))

        self.options.sort()

        with tempfile.NamedTemporaryFile(mode='wb',
                                         delete=False,
                                         suffix='.txt') as p:
            for font in self.options:
                f = SublimeFiglet(font=font[0],
                                  directory=font[1],
                                  width=80,
                                  justify="auto",
                                  direction="auto")
                p.write(("Font: %s Directory: %s\n" %
                         (font[0], font[1])).encode("utf-8"))
                p.write(
                    remove_trailing_ws(
                        f.renderText(text).replace('\r\n', '\n').replace(
                            '\r', '\n')).encode('utf-8'))
                p.write("\n\n".encode("utf-8"))

        self.window.open_file(p.name)