Allow use of Pygments to colorize source code
[deliverable/binutils-gdb.git] / gdb / python / lib / gdb / __init__.py
index 09d43b2a8aba1e9d0d49408036ab426a65d9e162..a1aac0079238949cd0470212b210747cb1115158 100644 (file)
@@ -210,3 +210,17 @@ def find_pc_line(pc):
     """find_pc_line (pc) -> Symtab_and_line.
 Return the gdb.Symtab_and_line object corresponding to the pc value."""
     return current_progspace().find_pc_line(pc)
+
+try:
+    from pygments import formatters, lexers, highlight
+    def colorize(filename, contents):
+        # Don't want any errors.
+        try:
+            lexer = lexers.get_lexer_for_filename(filename)
+            formatter = formatters.TerminalFormatter()
+            return highlight(contents, lexer, formatter)
+        except:
+            return None
+except:
+    def colorize(filename, contents):
+        return None
This page took 0.024693 seconds and 4 git commands to generate.