diff --git a/README.md b/README.md index 3d5c852..cd0702e 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ Durdraw _| |__ __ _____ __| |_____ _____ __ __ __ / _ | | | __| _ | __| _ | | | |\ /_____|_____|__|__|_____|__|___\____|________| | Durr.... - \_____________________________________________\| v 0.19.0 + \_____________________________________________\| v 0.19.1 ![durdraw-help-screen-256color](https://user-images.githubusercontent.com/261501/214016536-9413463f-2fe4-4298-8022-95daeabbe894.png) @@ -121,7 +121,7 @@ optional arguments: Set canvas height -m, --max Maximum canvas size for terminal (overrides -W and -H) --nomouse Disable mouse support - -A, --ansi IBM-PC ANSI Art Mode - Use F1-F10 keys for Code Page 437 extended ASCII (IBM- + -A, --ibmpc IBM-PC ANSI Art Mode - Use F1-F10 keys for Code Page 437 extended ASCII (IBM- PC) block characters -u UNDOSIZE, --undosize UNDOSIZE Set the number of undo history states - default is 100. More requires more diff --git a/durdraw/durdraw_appstate.py b/durdraw/durdraw_appstate.py index d30d732..8439752 100644 --- a/durdraw/durdraw_appstate.py +++ b/durdraw/durdraw_appstate.py @@ -10,9 +10,10 @@ class AppState(): """ run-time app state, separate from movie options (Options()) """ - def __init__(self): + def __init__(self): # User friendly defeaults self.curOpenFileName = "" self.colorMode = "256" # or 16, or possibly "none" or "true" or "rgb" (24 bit rgb "truecolor") + self.charEncoding = 'utf-8' # or cp437, aka ibm-pc self.cursorMode = "Move" # Move/Select, Draw and Color self.playOnlyMode = False self.playNumberOfTimes = 0 # 0 = loop forever, default @@ -20,7 +21,8 @@ def __init__(self): self.PIL = self.checkForPIL() self.undoHistorySize = 100 # How far back our undo history can self.playbackRange = (1,1) - self.drawChar = '$' + #self.drawChar = '$' + self.drawChar = b'\xE2\x96\x88' self.colorPickChar = chr(9608) # unicode block character, for displaying colors in color pickers self.hasMouse = True # replace with equivalent curses.has_mouse() self.helpMov = None diff --git a/durdraw/durdraw_file.py b/durdraw/durdraw_file.py index 4093a03..27f66bd 100644 --- a/durdraw/durdraw_file.py +++ b/durdraw/durdraw_file.py @@ -8,9 +8,10 @@ from durdraw.durdraw_options import Options from durdraw.durdraw_movie import Movie -def serialize_to_json_file(opts, movie, file_path, gzipped=True): +def serialize_to_json_file(opts, appState, movie, file_path, gzipped=True): """ Takes live Durdraw movie objects and serializes them out to a JSON files """ + colorMode = appState.colorMode if gzipped: opener = gzip.open else: @@ -18,10 +19,11 @@ def serialize_to_json_file(opts, movie, file_path, gzipped=True): with opener(file_path, 'wt') as f: movieDataHeader = { 'formatVersion': opts.saveFileFormat, - #'colorFormat': 'ansi-16', # ansi-16, xterm-256 - 'colorFormat': 'xterm-256', # ansi-16, xterm-256 + #'colorFormat': 'xterm-256', # ansi-16, xterm-256 + 'colorFormat': colorMode, # ansi-16, xterm-256 'preferredFont': 'fixed', # fixed, vga, amiga, etc. - 'encoding': 'Utf-8', + #'encoding': 'Utf-8', + 'encoding': appState.charEncoding, 'name': '', 'artist': '', 'framerate': opts.framerate, @@ -74,6 +76,22 @@ def clean_up_json_output(json_str): json_data = json_data.replace("\n ],", "],") return json_data +def get_dur_file_colorMode_and_charMode(f): + """ Returns the color mode and encoding used by the file """ + f.seek(0) + try: + loadedMovieData = json.load(f) + except Exception as E: + return False + colorMode = loadedMovieData['DurMovie']['colorFormat'] + charEncoding = loadedMovieData['DurMovie']['encoding'] + # convert from file format 5 to 6 + if colorMode == 'xterm-256': + colorMode = '256' + if charEncoding == 'Utf-8': + charEncoding = 'utf-8' + return colorMode, charEncoding + def open_json_dur_file(f): """ Loads json file into opts and movie objects. Takes an open file object. Returns the opts and mov objects, encased in a list object. @@ -84,6 +102,7 @@ def open_json_dur_file(f): loadedMovieData = json.load(f) except Exception as E: return False + width = loadedMovieData['DurMovie']['sizeX'] height = loadedMovieData['DurMovie']['sizeY'] newOpts = Options(width=width, height=height) diff --git a/durdraw/durdraw_options.py b/durdraw/durdraw_options.py index b435414..cf70333 100644 --- a/durdraw/durdraw_options.py +++ b/durdraw/durdraw_options.py @@ -6,8 +6,9 @@ def __init__(self, width=80, height=23): # default options self.framerate = 2.0 self.sizeX = width self.sizeY = height - self.saveFileFormat = 5 # save file format version number - # version 4 is pickle, version 5 is JSON + self.saveFileFormat = 6 # save file format version number + # version 4 is pickle, version 5 is JSON, version 6 saves color and + # character encoding formats def toJSON(self): return json.dumps(self, default=lambda o: o.__dict__, sort_keys=True, indent=4) diff --git a/durdraw/durdraw_ui_curses.py b/durdraw/durdraw_ui_curses.py index db9c2e9..bf44013 100644 --- a/durdraw/durdraw_ui_curses.py +++ b/durdraw/durdraw_ui_curses.py @@ -47,16 +47,18 @@ def __init__(self, app): if self.appState.colorMode == "256": if self.ansi.initColorPairs_hicolor(): if self.appState.playOnlyMode == False: - print("High Color Mode Enabled") # 256 color mode + #print("High Color Mode Enabled") # 256 color mode self.appState.loadHelpFile(self.appState.durhelp256_fullpath) else: self.appState.colorMode = "16" - if self.appState.playOnlyMode == False: - print("16 Color Mode Enabled. Change your TERM environment variable for 256 color support") + #if self.appState.playOnlyMode == False: + # print("16 Color Mode Enabled. Change your TERM environment variable for 256 color support") time.sleep(1) time.sleep(2) if self.appState.colorMode == "16": self.ansi.initColorPairs_cga() + print(f"Color mode: {self.appState.colorMode}") + time.sleep(2) #if self.appState.colorMode == "16": # self.ansi.initColorPairs_cga() # set up ncurses color pairs and fg/bg map - 16 color #self.ansi.initColorPairs() # set up ncurses color pairs and fg/bg map @@ -344,6 +346,10 @@ def testWindowSize(self): self.smallWindowMode() # go into small window loop.stdscr if self.realmaxX < (self.mov.sizeX-4): self.smallWindowMode() # go into small window loop.stdscr + if (self.realmaxY <= self.mov.sizeY): + self.appState.drawBorders = False + if (self.realmaxY > self.mov.sizeY): + self.appState.drawBorders = True def smallWindowMode(self): """Clear the screen, draw a small message near 0,0 that the window @@ -1321,8 +1327,6 @@ def mainLoop(self): self.xy[0] = mouseY self.insertChar(ord(' '), fg=self.colorfg, bg=self.colorbg, x=mouseX, y=mouseY, pushClip=False) elif self.appState.cursorMode == "Eyedrop": # Change the color under the cursor - self.xy[1] = mouseX + 1 # set cursor position - self.xy[0] = mouseY self.eyeDrop(mouseX, mouseY) elif self.pressingButton: self.pressingButton = False @@ -1611,6 +1615,11 @@ def loadFromFile(self, shortfile, loadFormat): # shortfile = non full path file if (f.read(12) == b'\x7b\x0a\x20\x20\x22\x44\x75\x72\x4d\x6f\x76\x69'): # {. "DurMov if self.appState.debug: self.notify(f"JSON found. Loading JSON dur file.") f.seek(0) + fileColorMode, fileCharEncoding = durfile.get_dur_file_colorMode_and_charMode(f) + if fileColorMode != self.appState.colorMode: + self.notify(f"Warning: File uses {fileColorMode} color mode, but Durdraw is in {self.appState.colorMode} color mode.", pause=True) + if fileCharEncoding != self.appState.charEncoding: + self.notify(f"Warning: File uses {fileCharEncoding} character encoding, but Durdraw is in {self.appState.charEncoding} mode.", pause=True) newMovie = durfile.open_json_dur_file(f) self.opts = newMovie['opts'] self.mov = newMovie['mov'] @@ -1809,9 +1818,9 @@ def saveDur2File(self, filename, gzipped=True): #movieDataHeader = {'format': 'Durdraw file', 'framerate': self.opts.framerate, 'sizeX': self.opts.sizeX, 'sizeY': self.opts.sizeY, 'fileFormatVersion': self.opts.saveFileFormat } #movieDump = [self.opts, self.mov] if gzipped: - durfile.serialize_to_json_file(self.opts, self.mov, filename) + durfile.serialize_to_json_file(self.opts, self.appState, self.mov, filename) else: - durfile.serialize_to_json_file(self.opts, self.mov, filename, gzipped=False) + durfile.serialize_to_json_file(self.opts, self.appSTate, self.mov, filename, gzipped=False) return True def saveAsciiFile(self, filename): diff --git a/durdraw/main.py b/durdraw/main.py index a031478..0faeb46 100644 --- a/durdraw/main.py +++ b/durdraw/main.py @@ -24,7 +24,7 @@ def undosize(size_s): raise argparse.ArgumentTypeError("Undo size must be between 1 and 1000.") def main(): - DUR_VER = '0.19.0' + DUR_VER = '0.19.1' DUR_FILE_VER = 5 DEBUG_MODE = False # debug = makes debug_write available, sends more notifications durlogo = ''' @@ -57,7 +57,7 @@ def main(): parser.add_argument("-m", "--max", help="Maximum canvas size for terminal (overrides -W and -H)", action="store_true") parser.add_argument("--nomouse", help="Disable mouse support", action="store_true") - parser.add_argument("-A", "--ansi", help="IBM-PC ANSI Art Mode - Use F1-F10 keys for Code Page 437 extended ASCII (IBM-PC) block characters", action="store_true") + parser.add_argument("-A", "--ibmpc", help="IBM-PC ANSI Art Mode - Use F1-F10 keys for Code Page 437 extended ASCII (IBM-PC/MS-DOS) block characters. (Needs CP437 capable terminal and font)", action="store_true") parser.add_argument("-u", "--undosize", help="Set the number of undo history states - default is 100. More requires more RAM, less saves RAM.", nargs=1, type=int) parser.add_argument("-V", "--version", help="Show version number and exit", action="store_true") @@ -104,11 +104,10 @@ def main(): app.colorMode = "256" if args.locolor: app.colorMode = "16" - if args.ansi: - app.ansiArtMode = True + if args.ibmpc: app.charEncoding = 'ibm-pc' + app.drawChar = '$' else: - app.ansiArtMode = False app.charEncoding = 'utf-8' durhelp_fullpath = pathlib.Path(__file__).parent.joinpath("help/durhelp.dur") if args.blackbg: @@ -160,7 +159,8 @@ def main(): print("\nCaught interrupt, exiting.") exit(0) else: - time.sleep(3) + pass + #time.sleep(3) if args.play: app.playOnlyMode = True ui = UI_Curses(app) diff --git a/setup.py b/setup.py index 1f4bdd5..9352bbf 100644 --- a/setup.py +++ b/setup.py @@ -6,7 +6,7 @@ setup( name='durdraw', - version='0.19.0', + version='0.19.1', author='Sam Foster', author_email='samfoster@gmail.com', description='Animated Color ASCII and Unicode Art Editor',