@@ -2864,6 +2864,27 @@ def save(self):
28642864 prompting = False
28652865 return None
28662866 self .clearStatusLine ()
2867+ if saveFormat == 'ansi' : # ansi = escape codes for colors+ascii
2868+ prompting = True
2869+ while prompting :
2870+ # Ask if they want CP437 or Utf-8 encoding
2871+ self .clearStatusLine ()
2872+ self .promptPrint (f"File encoding? [C]P437, [U]tf-8? (default: { self .appState .charEncoding } ): " )
2873+ c = self .stdscr .getch ()
2874+ time .sleep (0.01 )
2875+ if c == ord ('c' ):
2876+ encoding = "cp437"
2877+ prompting = False
2878+ elif c == ord ('u' ):
2879+ encoding = "utf-8"
2880+ prompting = False
2881+ elif c in [13 , curses .KEY_ENTER ]:
2882+ encoding = "default"
2883+ prompting = False
2884+ elif c == 27 : # 27 = esc = cancel
2885+ self .notify ("Canceled. File not saved." )
2886+ prompting = False
2887+ return False
28672888 if saveFormat in ['png' , 'gif' ]:
28682889 self .promptPrint ("Which font? IBM PC [A]NSI, AM[I]GA: " )
28692890 prompting = True
@@ -2908,7 +2929,10 @@ def save(self):
29082929 prompting = False
29092930 return None
29102931 self .clearStatusLine ()
2911- self .promptPrint (f"Enter file name to save as ({ saveFormat } ) [{ self .appState .curOpenFileName } ]: " )
2932+ if saveFormat == "ansi" :
2933+ self .promptPrint (f"Enter file name to save as ({ saveFormat } /{ encoding } ) [{ self .appState .curOpenFileName } ]: " )
2934+ else :
2935+ self .promptPrint (f"Enter file name to save as ({ saveFormat } ) [{ self .appState .curOpenFileName } ]: " )
29122936 curses .echo ()
29132937 filename = str (self .stdscr .getstr ().decode ('utf-8' ))
29142938 curses .noecho ()
@@ -2944,7 +2968,7 @@ def save(self):
29442968 if saveFormat == 'html' : # dur2 = serialized json, plaintext
29452969 saved = self .saveHtmlFile (filename , gzipped = False )
29462970 if saveFormat == 'ansi' : # ansi = escape codes for colors+ascii
2947- saved = self .saveAnsiFile (filename )
2971+ saved = self .saveAnsiFile (filename , encoding = encoding )
29482972 if saveFormat == 'irc' : # ansi = escape codes for colors+ascii
29492973 saved = self .saveAnsiFile (filename , ircColors = True )
29502974 if saveFormat == 'png' : # png = requires ansi love
@@ -3010,10 +3034,15 @@ def saveAsciiFile(self, filename):
30103034 f .close ()
30113035 return True
30123036
3013- def saveAnsiFile (self , filename , lastLineNum = False , lastColNum = False , firstColNum = False , firstLineNum = None , ircColors = False ):
3037+ def saveAnsiFile (self , filename , lastLineNum = False , lastColNum = False , firstColNum = False , firstLineNum = None , ircColors = False , encoding = "default" ):
30143038 """ Saves current frame of current movie to ansi file """
30153039 try :
3016- f = open (filename , 'w' )
3040+ if encoding == "default" :
3041+ f = open (filename , 'w' )
3042+ elif encoding == "cp437" :
3043+ f = open (filename , 'w' , encoding = "cp437" )
3044+ elif encoding == "utf-8" :
3045+ f = open (filename , 'w' , encoding = "utf-8" )
30173046 except :
30183047 self .notify ("Could not open file for writing. (Press any key to continue)" , pause = True )
30193048 return False
@@ -3056,14 +3085,22 @@ def saveAnsiFile(self, filename, lastLineNum=False, lastColNum=False, firstColNu
30563085 string = string + '\n '
30573086 else :
30583087 string = string + '\r \n '
3059- f .write (string )
3088+ try :
3089+ f .write (string )
3090+ saved = True
3091+ except UnicodeEncodeError :
3092+ self .notify ("Error: Some characters were not compatible with this encoding. File not saved." )
3093+ saved = False
3094+ #f.close()
3095+ #return False
30603096 if ircColors :
30613097 string2 = string + '\n '
30623098 else :
30633099 f .write ('\033 [0m' ) # color attributes off
30643100 string2 = string + '\r \n ' # final CR+LF (DOS style newlines)
30653101 f .close ()
3066- return True
3102+ #return True
3103+ return saved
30673104
30683105 def findLastMovieLine (self , movie ):
30693106 """ Cycle through the whole movie, figure out the lowest numbered
0 commit comments