binutils-gdb/gdb/python
Tom Tromey cbe5657196 Add output styles to gdb
This adds some output styling to the CLI.

A style is currently a foreground color, a background color, and an
intensity (dim or bold).  (This list could be expanded depending on
terminal capabilities.)

A style can be applied while printing.  For ui-out, this is done by
passing the style constant as an argument.  For low-level cases,
fprintf_styled and fputs_styled are provided.

Users can control the style via a number of new set/show commands.  In
the interest of not typing many nearly-identical documentation
strings, I automated this.  On the down side, this is not very
i18n-friendly.

I've chose some default colors to use.  I think it would be good to
enable this by default, so that when users start the new gdb, they
will see the new feature.

Stylizing is done if TERM is set and is not "dumb".  This could be
improved when the TUI is available by using the curses has_colors
call.  That is, the lowest layer could call this without committing to
using curses everywhere; see my other patch for TUI colorizing.

I considered adding a new "set_style" method to ui_file.  However,
because the implementation had to interact with the pager code, I
didn't take this approach.  But, one idea might be to put the isatty
check there and then have it defer to the lower layers.

gdb/ChangeLog
2018-12-28  Tom Tromey  <tom@tromey.com>

	* utils.h (set_output_style, fprintf_styled)
	(fputs_styled): Declare.
	* utils.c (applied_style, desired_style): New globals.
	(emit_style_escape, set_output_style): New function.
	(prompt_for_continue): Emit style escapes.
	(fputs_maybe_filtered): Likewise.
	(fputs_styled, fprintf_styled): New functions.
	* ui-out.h (enum class ui_out_style_kind): New.
	(class ui_out) <field_string, field_stream, do_field_string>: Add
	style parameter.
	* ui-out.c (ui_out::field_stream, ui_out::field_string): Add style
	parameter.
	* tui/tui-out.h (class tui_ui_out) <do_field_string>: Add style
	parameter.
	* tui/tui-out.c (tui_ui_out::do_field_string): Add style
	parameter.
	(tui_ui_out::do_field_string): Update.
	* tracepoint.c (print_one_static_tracepoint_marker): Style
	output.
	* stack.c (print_frame_info, print_frame): Style output.
	* source.c (print_source_lines_base): Style output.
	* skip.c (info_skip_command): Style output.
	* record-btrace.c (btrace_call_history_src_line): Style output.
	(btrace_call_history): Likewise.
	* python/py-framefilter.c (py_print_frame): Style output.
	* mi/mi-out.h (class mi_ui_out) <do_field_string>: Add style
	parameter.
	* mi/mi-out.c (mi_ui_out::do_table_header)
	(mi_ui_out::do_field_int): Update.
	(mi_ui_out::do_field_string): Update.
	* disasm.c (gdb_pretty_print_disassembler::pretty_print_insn):
	Style output.
	* cli/cli-style.h: New file.
	* cli/cli-style.c: New file.
	* cli-out.h (class cli_ui_out) <do_field_string>: Add style
	parameter.
	* cli-out.c (cli_ui_out::do_table_header)
	(cli_ui_out::do_field_int, cli_ui_out::do_field_skip): Update.
	(cli_ui_out::do_field_string): Add style parameter.  Style the
	output.
	* breakpoint.c (print_breakpoint_location): Style output.
	(update_static_tracepoint): Likewise.
	* Makefile.in (SUBDIR_CLI_SRCS): Add cli-style.c.
	(HFILES_NO_SRCDIR): Add cli-style.h.

gdb/testsuite/ChangeLog
2018-12-28  Tom Tromey  <tom@tromey.com>

	* gdb.base/style.exp: New file.
	* gdb.base/style.c: New file.
2018-12-28 12:49:49 -07:00
..
lib/gdb Fix output indentation for "info pretty-printers" 2018-11-08 16:17:01 -07:00
py-all-events.def Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
py-arch.c Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
py-auto-load.c Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
py-block.c Return gdbpy_ref from gdb_py_object_from_*longest 2018-11-04 08:01:00 -07:00
py-bpevent.c gdb/python: Use copy-initialization more when possible 2018-08-24 22:57:16 +01:00
py-breakpoint.c Use gdbpy_convert_exception in a few more spots 2018-12-27 13:34:38 -07:00
py-cmd.c Use gdbpy_convert_exception in a few more spots 2018-12-27 13:34:38 -07:00
py-continueevent.c Change thread_to_thread_object to return a new reference 2018-09-16 07:25:57 -06:00
py-event-types.def Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
py-event.c Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
py-event.h Change thread_to_thread_object to return a new reference 2018-09-16 07:25:57 -06:00
py-events.h Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
py-evtregistry.c Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
py-evts.c Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
py-exitedevent.c gdb/python: Use copy-initialization more when possible 2018-08-24 22:57:16 +01:00
py-finishbreakpoint.c Use thread_info and inferior pointers more throughout 2018-06-21 17:09:31 +01:00
py-frame.c Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
py-framefilter.c Add output styles to gdb 2018-12-28 12:49:49 -07:00
py-function.c gdb/python: Make convert_values_to_python return gdbpy_ref<> 2018-10-25 12:20:18 +01:00
py-gdb-readline.c Remove "repeat" argument from command_line_input 2018-08-17 16:39:06 -06:00
py-inferior.c Remove more calls to xfree from Python 2018-12-27 10:50:43 -07:00
py-infevents.c gdb/python: Use copy-initialization more when possible 2018-08-24 22:57:16 +01:00
py-infthread.c Change thread_to_thread_object to return a new reference 2018-09-16 07:25:57 -06:00
py-instruction.c Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
py-instruction.h Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
py-lazy-string.c Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
py-linetable.c Return gdbpy_ref from gdb_py_object_from_*longest 2018-11-04 08:01:00 -07:00
py-newobjfileevent.c Change objfile_to_objfile_object to return a new reference 2018-09-16 07:25:56 -06:00
py-objfile.c Remove more calls to xfree from Python 2018-12-27 10:50:43 -07:00
py-param.c Use gdbpy_convert_exception in a few more spots 2018-12-27 13:34:38 -07:00
py-prettyprint.c Return gdbpy_ref from gdbpy_get_varobj_pretty_printer 2018-11-04 08:01:01 -07:00
py-progspace.c Return gdbpy_ref from some Python string functions 2018-11-04 08:01:01 -07:00
py-record-btrace.c Remove more calls to xfree from Python 2018-12-27 10:50:43 -07:00
py-record-btrace.h Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
py-record-full.c Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
py-record-full.h Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
py-record.c Use thread_info and inferior pointers more throughout 2018-06-21 17:09:31 +01:00
py-record.h Use thread_info and inferior pointers more throughout 2018-06-21 17:09:31 +01:00
py-ref.h Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
py-signalevent.c gdb/python: Use copy-initialization more when possible 2018-08-24 22:57:16 +01:00
py-stopevent.c Change thread_to_thread_object to return a new reference 2018-09-16 07:25:57 -06:00
py-stopevent.h Update copyright year range in all GDB files 2018-01-02 07:38:06 +04:00
py-symbol.c Update symbol domain and location values for Python 2018-10-06 23:20:55 -06:00
py-symtab.c Remove more calls to xfree from Python 2018-12-27 10:50:43 -07:00
py-threadevent.c Simplify uses of thread_to_thread_object 2018-09-16 23:36:54 -06:00
py-type.c Return gdbpy_ref from gdb_py_object_from_*longest 2018-11-04 08:01:00 -07:00
py-unwind.c Consolidate some Python exception-printing functions 2018-12-27 13:34:39 -07:00
py-utils.c Translate PyExc_KeyboardInterrupt to gdb "quit" 2018-12-27 13:34:39 -07:00
py-value.c Use gdbpy_convert_exception in a few more spots 2018-12-27 13:34:38 -07:00
py-varobj.c Don't steal references in the gdb Python code 2018-09-16 23:48:21 -06:00
py-xmethods.c invoke_xmethod & array_view 2018-11-21 12:06:20 +00:00
python-config.py configure uses incorrect link order when testing libpython 2018-05-04 10:08:09 -04:00
python-internal.h Consolidate some Python exception-printing functions 2018-12-27 13:34:39 -07:00
python.c Consolidate some Python exception-printing functions 2018-12-27 13:34:39 -07:00
python.h python: Make gdb.execute("show commands") work (PR 23669) 2018-09-17 08:26:24 -04:00