Skip to content

Commit

Permalink
Pre-compute level max length
Browse files Browse the repository at this point in the history
  • Loading branch information
efernandez committed Feb 19, 2018
1 parent 47e303b commit 8a0d767
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions clients/rospy/src/rospy/rosconsole.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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():
Expand Down

0 comments on commit 8a0d767

Please sign in to comment.