Fix the memory bug for real this time + calculate color changes correctly.
This commit is contained in:
parent
c6dd9513b4
commit
ba4d33373d
1 changed files with 2 additions and 10 deletions
12
pat.py
12
pat.py
|
@ -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():
|
read_result = file.read(bytes_to_read)
|
||||||
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)
|
|
||||||
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
|
||||||
|
|
Loading…
Reference in a new issue