Skip to content

Commit

Permalink
0.19.1: Eyedrop no longer moves the cursor. Dur files now save color …
Browse files Browse the repository at this point in the history
…and char encoding modes. Warnings if files are attempted to load in wrong modes. Default drawing character is now block. --ansi command-line changed to --ibmpc for cp437. Bumped internal version number to 6.
  • Loading branch information
cmang committed May 13, 2023
1 parent facc113 commit 3449209
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 24 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions durdraw/durdraw_appstate.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,19 @@

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
self.ansiLove = self.isAppAvail("ansilove")
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
Expand Down
27 changes: 23 additions & 4 deletions durdraw/durdraw_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,22 @@
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:
opener = open
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,
Expand Down Expand Up @@ -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.
Expand All @@ -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)
Expand Down
5 changes: 3 additions & 2 deletions durdraw/durdraw_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
23 changes: 16 additions & 7 deletions durdraw/durdraw_ui_curses.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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']
Expand Down Expand Up @@ -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):
Expand Down
12 changes: 6 additions & 6 deletions durdraw/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '''
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit 3449209

Please sign in to comment.