rosconsole_overlay_text.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 
00003 import re
00004 
00005 from jsk_rviz_plugins.msg import OverlayText
00006 from rosgraph_msgs.msg import Log
00007 import rospy
00008 
00009 
00010 def colored_message(msg):
00011     cmsg = msg.msg
00012     cmsg = re.sub(r'\x1b\[31m', '<span style="color: red">', cmsg)
00013     cmsg = re.sub(r'\x1b\[32m', '<span style="color: green">', cmsg)
00014     cmsg = re.sub(r'\x1b\[33m', '<span style="color: yellow">', cmsg)
00015     cmsg = re.sub(r'\x1b\[34m', '<span style="color: blue">', cmsg)
00016     cmsg = re.sub(r'\x1b\[35m', '<span style="color: purple">', cmsg)
00017     cmsg = re.sub(r'\x1b\[36m', '<span style="color: cyan">', cmsg)
00018     cmsg = re.sub(r'\x1b\[0m', '</span>', cmsg)
00019     if msg.level == Log.DEBUG:
00020         return '<span style="color: rgb(120,120,120);">%s</span>' % cmsg
00021     elif msg.level == Log.INFO:
00022         return '<span style="color: white;">%s</span>' % cmsg
00023     elif msg.level == Log.WARN:
00024         return '<span style="color: yellow;">%s</span>' % cmsg
00025     elif msg.level == Log.ERROR:
00026         return '<span style="color: red;">%s</span>' % cmsg
00027     elif msg.level == Log.FATAL:
00028         return '<span style="color: red;">%s</span>' % cmsg
00029 
00030 
00031 def callback(msg):
00032     for exclude_regex in exclude_regexes:
00033         if re.match(exclude_regex, msg.msg):
00034             return
00035 
00036     global lines
00037     if msg.name not in ignore_nodes:
00038         if msg.name in nodes or len(nodes) == 0:
00039             if len(nodes_regexp) == 0 or nodes_regexp_compiled.match(msg.name):
00040                 if reverse_lines:
00041                     lines = [colored_message(msg)] + lines
00042                     if len(lines) > line_buffer_length:
00043                         lines = lines[0:line_buffer_length]
00044                 else:
00045                     lines = lines + [colored_message(msg)]
00046                     if len(lines) > line_buffer_length:
00047                         lines = lines[-line_buffer_length:]
00048                 text = OverlayText()
00049                 text.left = 20
00050                 text.top = 20
00051                 text.width = 1200
00052                 text.height = 1200
00053                 text.fg_color.a = 1.0
00054                 text.fg_color.r = 0.3
00055                 text.text_size = 12
00056                 text.text = "\n".join(lines)
00057                 pub.publish(text)
00058 
00059 
00060 if __name__ == "__main__":
00061     rospy.init_node("rosconsole_overlay_text")
00062     nodes = rospy.get_param("~nodes", [])
00063     nodes_regexp = rospy.get_param("~nodes_regexp", "")
00064     if nodes_regexp:
00065         nodes_regexp_compiled = re.compile(nodes_regexp)
00066     ignore_nodes = rospy.get_param("~ignore_nodes", [])
00067     exclude_regexes = rospy.get_param("~exclude_regexes", [])
00068     line_buffer_length = rospy.get_param("~line_buffer_length", 100)
00069     reverse_lines = rospy.get_param("~reverse_lines", True)
00070     lines = []
00071     sub = rospy.Subscriber("/rosout", Log, callback)
00072     pub = rospy.Publisher("~output", OverlayText, queue_size=1)
00073     rospy.spin()


jsk_rviz_plugins
Author(s): Kei Okada , Yohei Kakiuchi , Shohei Fujii , Ryohei Ueda
autogenerated on Wed May 1 2019 02:40:22