Skip to content

Commit c15f3b6

Browse files
committed
0.22.2 - Saving ANSI now asks if you want CP437 or Utf8 encoding
1 parent 3ae4e7e commit c15f3b6

File tree

6 files changed

+46
-9
lines changed

6 files changed

+46
-9
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Durdraw
55
_| |__ __ _____ __| |_____ _____ __ __ __
66
/ _ | | | __| _ | __| _ | | | |\
77
/_____|_____|__|__|_____|__|___\____|________| |
8-
\_____________________________________________\| v 0.22.1
8+
\_____________________________________________\| v 0.22.2
99

1010

1111
![Durdraw-0 20-demo](https://github.com/cmang/durdraw/assets/261501/ce539865-2e84-4423-92af-cd9ddeeb02ce)

durdraw/durdraw_ui_curses.py

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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

durdraw/help/durhelp-16-long.dur

131 Bytes
Binary file not shown.

durdraw/help/durhelp-256-long.dur

385 Bytes
Binary file not shown.

durdraw/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def undosize(size_s):
2626
raise argparse.ArgumentTypeError("Undo size must be between 1 and 1000.")
2727

2828
def main():
29-
DUR_VER = '0.22.1'
29+
DUR_VER = '0.22.2'
3030
DUR_FILE_VER = 7
3131
DEBUG_MODE = False # debug = makes debug_write available, sends verbose notifications
3232
durlogo = '''

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
setup(
88
name='durdraw',
9-
version='0.22.1',
9+
version='0.22.2',
1010
author='Sam Foster',
1111
author_email='samfoster@gmail.com',
1212
description='Animated Color ASCII and Unicode Art Editor',

0 commit comments

Comments
 (0)