From 8a0d76721290eba1ec4af504267cbff8018a5292 Mon Sep 17 00:00:00 2001 From: Enrique Fernandez Date: Mon, 19 Feb 2018 14:02:59 -0500 Subject: [PATCH] Pre-compute level max length --- clients/rospy/src/rospy/rosconsole.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/clients/rospy/src/rospy/rosconsole.py b/clients/rospy/src/rospy/rosconsole.py index ac4ab98136..118d9d4c02 100644 --- a/clients/rospy/src/rospy/rosconsole.py +++ b/clients/rospy/src/rospy/rosconsole.py @@ -154,6 +154,8 @@ class RosConsoleEcho(object): 'FATAL': 95, # Light magenta } + LEVEL_MAX_LENGTH = max([len(level) for level in LEVEL_COLOR.keys()]) + def __init__(self, options): self._filter = re.compile(options.filter) self._level = getattr(Log, options.level.upper()) @@ -166,9 +168,10 @@ def __init__(self, options): rospy.Subscriber(options.topic, Log, callback) def _stringify(self, level): - string = level.ljust(5) + string = level.ljust(RosConsoleEcho.LEVEL_MAX_LENGTH) - return string if self._nocolor else '\033[{}m{}\033[0m'.format(self.LEVEL_COLOR[level], string) + return string if self._nocolor else \ + '\033[{}m{}\033[0m'.format(self.LEVEL_COLOR[level], string) @staticmethod def get_levels():