From 024680e96b725d9611ed1649365b24cd900ba3b6 Mon Sep 17 00:00:00 2001 From: Sven Augustin Date: Sun, 24 Oct 2021 12:11:34 +0200 Subject: [PATCH] shorten long entries in the Value column --- inspector.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/inspector.py b/inspector.py index 783f61b..c549ccd 100644 --- a/inspector.py +++ b/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()