shorten long entries in the Value column
This commit is contained in:
14
inspector.py
14
inspector.py
@ -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()
|
||||
|
Reference in New Issue
Block a user