mirror of
https://github.com/neovim/neovim.git
synced 2025-11-21 17:46:30 +00:00
scripts: Improve shadacat to work with unknown items
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
#!/usr/bin/env python3.4
|
#!/usr/bin/env python3.4
|
||||||
|
|
||||||
|
import os
|
||||||
import sys
|
import sys
|
||||||
import codecs
|
import codecs
|
||||||
|
|
||||||
@@ -58,18 +59,28 @@ def mnormalize(o):
|
|||||||
return ctable.get(type(o), idfunc)(o)
|
return ctable.get(type(o), idfunc)(o)
|
||||||
|
|
||||||
|
|
||||||
with open(sys.argv[1], 'rb') as fp:
|
fname = sys.argv[1]
|
||||||
|
poswidth = len(str(os.stat(fname).st_size or 1000))
|
||||||
|
|
||||||
|
|
||||||
|
with open(fname, 'rb') as fp:
|
||||||
unpacker = msgpack.Unpacker(file_like=fp, read_size=1)
|
unpacker = msgpack.Unpacker(file_like=fp, read_size=1)
|
||||||
|
max_type = max(typ.value for typ in EntryTypes)
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
pos = fp.tell()
|
pos = fp.tell()
|
||||||
typ = EntryTypes(unpacker.unpack())
|
typ = unpacker.unpack()
|
||||||
except msgpack.OutOfData:
|
except msgpack.OutOfData:
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
timestamp = unpacker.unpack()
|
timestamp = unpacker.unpack()
|
||||||
time = datetime.fromtimestamp(timestamp)
|
time = datetime.fromtimestamp(timestamp)
|
||||||
length = unpacker.unpack()
|
length = unpacker.unpack()
|
||||||
entry = unpacker.unpack()
|
if typ > max_type:
|
||||||
print('{0:4} {1:13} {2} {3:5} {4!r}'.format(
|
entry = fp.read(length)
|
||||||
pos, typ.name, time.isoformat(), length, mnormalize(entry)))
|
typ = EntryTypes.Unknown
|
||||||
|
else:
|
||||||
|
entry = unpacker.unpack()
|
||||||
|
typ = EntryTypes(typ)
|
||||||
|
print('%*u %13s %s %5u %r' % (
|
||||||
|
poswidth, pos, typ.name, time.isoformat(), length, mnormalize(entry)))
|
||||||
|
|||||||
Reference in New Issue
Block a user