shorten long entries in the Value column

This commit is contained in:
2021-10-24 12:11:34 +02:00
parent 5385052095
commit 024680e96b

View File

@ -79,7 +79,7 @@ class VariableInspector(object, metaclass=Singleton):
def format_line(k, v):
return LINE.format(k, typename(v), size(v), v)
return LINE.format(k, typename(v), size(v), format_value(v))
def sorted_naturally(iterable, reverse=False):
natural = lambda item: [int(c) if c.isdigit() else c.casefold() for c in RE_DIGITS.split(str(item))]
@ -100,6 +100,18 @@ def size(obj):
except TypeError:
return ""
def format_value(obj): #TODO: make magic numbers configurable
res = str(obj)
# try if separate lines can be used to shorten
splitted = res.split("\n")
if len(splitted) > 4:
res = splitted[0] + " ... " + splitted[-1]
# if still too long (or no lines), cut the middle part
if len(res) < 120:
return res
res = res[:50] + " ... " + res[-50:]
return res
inspector = VariableInspector()