def saveAnsimationFile(self, filename, lastLineNum=False, lastColNum=False, firstColNum=False, firstLineNum=None, ircColors=False, encoding="default", play_times=False):
        """ Saves current frame of current movie to ansi file """
        # some escape codes from https://stackoverflow.com/questions/4842424/list-of-ansi-color-escape-sequences
        #print("\\033[<L>;<C>H or \\033[<L>;<C>f  - Put the cursor at line L and column C.")
        #print("\\033[<N>A                        - Move the cursor up N lines")
        #print("\\033[<N>B                        - Move the cursor down N lines")
        #print("\\033[<N>C                        - Move the cursor forward N columns")
        #print("\\033[<N>D                        - Move the cursor backward N columns\n")
        #print("\\033[2J                          - Clear the screen, move to (0,0)")
        ESC_CLS = "\033[2J"
        ESC_TOPLEFT = "\033[0;0H"

        if play_times == False:
            play_times = 1

        try:
            if encoding == "default":
                f = open(filename, 'w')
            elif encoding == "cp437":
                f = open(filename, 'w', encoding="cp437")
            elif encoding == "utf-8":
                f = open(filename, 'w', encoding="utf-8")
        except:
            self.notify("Could not open file for writing. (Press any key to continue)", pause=True)
            return False
        string = ''
        string = string + ESC_CLS
        string = string + ESC_TOPLEFT
        if not lastLineNum: # if we weren't told what lastLineNum is...
            # find it (last line we should save)
            lastLineNum = self.findFrameLastLine(self.mov.currentFrame)
            for frame in self.mov.frames:
                newLastLineNum = self.findFrameLastLine(frame)
                lastLineNum = max(newLastLineNum, lastLineNum)
                #if newLastLineNum > lastLineNum:
                #    lastLineNum = newLastLineNum
        if not lastColNum:
            lastColNum = self.findFrameLastCol(self.mov.currentFrame)
            for frame in self.mov.frames:
                newLastColNum = self.findFrameLastCol(frame)
                lastColNum = max(newLastColNum, lastColNum)
        if not firstColNum:
            firstColNum = 0 # Don't crop leftmost blank columns
        if not firstLineNum:
            #firstLineNum = self.findFrameFirstLine(self.mov.currentFrame)
            firstLineNum = 0

        for repeat_count in range(0, play_times):
            frameNum = 0
            for frame in self.mov.frames:
                string = string + ESC_TOPLEFT
                for lineNum in range(firstLineNum, lastLineNum):  # y == lines
                    for colNum in range(firstColNum, lastColNum):
                        char = self.mov.frames[frameNum].content[lineNum][colNum]
                        color = self.mov.frames[frameNum].newColorMap[lineNum][colNum]
                        colorFg = color[0]
                        colorBg = color[1]
                        if self.appState.colorMode == "256":
                            if self.appState.showBgColorPicker == False:
                                colorBg = 0 # black, I hope
                        try:
                            if ircColors:
                                colorCode = self.ansi.getColorCodeIrc(colorFg,colorBg)
                            else:
                                if self.appState.colorMode == "256":
                                    colorCode = self.ansi.getColorCode256(colorFg,colorBg)
                                else:
                                    colorCode = self.ansi.getColorCode(colorFg,colorBg)
                        except KeyError:
                            if ircColors:   # problem? set a default color
                                colorCode = self.ansi.getColorCodeIrc(1,0)
                            else:
                                colorCode = self.ansi.getColorCode(1,0)
                        # If we don't have extended ncurses 6 color pairs,
                        # we don't have background colors.. so write the background as black/0
                        string = string + colorCode + char
                    if ircColors:
                        string = string + '\n'
                    else:
                        string = string + '\r\n'
                frameNum += 1


        try:
            f.write(string)
            saved = True
        except UnicodeEncodeError as encodeError:
            self.notify("Error: Some characters were not compatible with this encoding. File not saved.", pause=True)
            self.notify(f"{encodeError}", pause=True)
            saved = False
            #f.close()
            #return False
        if ircColors:
            string2 = string + '\n'
        else:
            f.write('\033[0m') # color attributes off
            string2 = string + '\r\n'   # final CR+LF (DOS style newlines)
        f.close()
        #return True
        return saved
 Saves current frame of current movie to ansi file 
durdraw/durdraw_ui_curses.py