From f6474de9aacec990d44d2d65a337668b389efd99 Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Fri, 3 Jan 2020 13:59:27 -0700 Subject: Allow use of Pygments to colorize source code While GNU Source Highlight is good, it's also difficult to build and distribute. For one thing, it needs Boost. For another, it has an unusual configuration and installation setup. Pygments, a Python library, doesn't suffer from these issues, and so I thought it would be a reasonable fallback. This patch implements this idea. GNU Source Highlight is preferred, but if it is unavailable (or fails), the extension languages are tried. This patch also implements support for Pygments. Something similar could be done for Guile, using: https://dthompson.us/projects/guile-syntax-highlight.html However, I don't know enough about Guile internals to make this happen, so I have not done it here. gdb/ChangeLog 2020-01-21 Tom Tromey * source-cache.c (source_cache::ensure): Call ext_lang_colorize. * python/python.c (python_extension_ops): Update. (gdbpy_colorize): New function. * python/lib/gdb/__init__.py (colorize): New function. * extension.h (ext_lang_colorize): Declare. * extension.c (ext_lang_colorize): New function. * extension-priv.h (struct extension_language_ops) : New member. * cli/cli-style.c (_initialize_cli_style): Update help text. Change-Id: I5e21623ee05f1f66baaa6deaeca78b578c031bf4 --- gdb/extension.h | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'gdb/extension.h') diff --git a/gdb/extension.h b/gdb/extension.h index 5da0602..ca3fc14 100644 --- a/gdb/extension.h +++ b/gdb/extension.h @@ -22,6 +22,7 @@ #include "mi/mi-cmds.h" /* For PRINT_NO_VALUES, etc. */ #include "gdbsupport/array-view.h" +#include "gdbsupport/gdb_optional.h" struct breakpoint; struct command_line; @@ -309,4 +310,12 @@ extern void get_matching_xmethod_workers (struct type *type, const char *method_name, std::vector *workers); +/* Try to colorize some source code. FILENAME is the name of the file + holding the code. CONTENTS is the source code itself. This will + either a colorized (using ANSI terminal escapes) version of the + source code, or an empty value if colorizing could not be done. */ + +extern gdb::optional ext_lang_colorize + (const std::string &filename, const std::string &contents); + #endif /* EXTENSION_H */ -- cgit v1.1