Fix the memory bug for real this time + calculate color changes correctly.

This commit is contained in:
Lavender 2021-03-16 17:13:18 -07:00
parent c6dd9513b4
commit ba4d33373d
No known key found for this signature in database
GPG key ID: 2E313F589412D650

10
pat.py
View file

@ -26,20 +26,12 @@ if len(argv) == 1:
for arg in argv[1:]: for arg in argv[1:]:
try: try:
file = stdin if arg == "-" else open(arg, "r") file = stdin if arg == "-" else open(arg, "r")
if file.seekable():
file_length = file.seek(0, 2)
if file_length > bytes_to_read:
file.seek(file_length - bytes_to_read)
else:
file.seek(0)
read_result = file.read()
else:
read_result = file.read(bytes_to_read) read_result = file.read(bytes_to_read)
except Exception as e: except Exception as e:
print("Error reading %s: %s" % (file.name, e), file=stderr) print("Error reading %s: %s" % (file.name, e), file=stderr)
continue continue
changes = len(list(filter(lambda c: not c in whitespace, read_result))) changes = len(list(filter(lambda c: not c in whitespace, read_result))) - 1
step = 0 if changes == 0 else ColorInfo.AMOUNT / changes step = 0 if changes == 0 else ColorInfo.AMOUNT / changes
index = 0 index = 0