binutils-gdb/gdb/cli/cli-style.c
Philippe Waroquiers 590042fc45 Make first and last lines of 'command help documentation' consistent.
With this patch, the help docs now respect 2 invariants:
  * The first line of a command help is terminated by a '.' character.
  * The last character of a command help is not a newline character.

Note that the changes for the last invariant were done by Tom, as part of :
 [PATCH] Remove trailing newlines from help text
 https://sourceware.org/ml/gdb-patches/2019-06/msg00050.html
but some occurrences have been re-introduced since then.

Some help docs had to be rephrased/restructured to respect the above
invariants.

Before this patch, print_doc_line was printing the first line
of a command help documentation, but stopping at the first '.'
or ',' character.

This was giving inconsistent results :
  * The first line of command helps was sometimes '.' terminated,
    sometimes not.
  * The first line of command helps was not always designed to be
    readable/understandable/unambiguous when stopping at the first
    '.' or ',' character.

This e.g. created the following inconsistencies/problems:
< catch exception -- Catch Ada exceptions
< catch handlers -- Catch Ada exceptions
< catch syscall -- Catch system calls by their names
< down-silently -- Same as the `down' command
while the new help is:
> catch exception -- Catch Ada exceptions, when raised.
> catch handlers -- Catch Ada exceptions, when handled.
> catch syscall -- Catch system calls by their names, groups and/or numbers.
> down-silently -- Same as the `down' command, but does not print anything.

Also, the command help doc should not be terminated by a newline
character, but this was not respected by all commands.
The cli-option -OPT framework re-introduced some occurences.
So, the -OPT build help framework was changed to not output newlines at the
end of %OPTIONS% replacement.

This patch changes the help documentations to ensure the 2 invariants
given above.

It implied to slightly rephrase or restructure some help docs.

Based on the above invariants, print_doc_line (called by
'apropos' and 'help' commands to print the first line of a command
help) now outputs the full first line of a command help.

This all results in a lot of small changes in the produced help docs.
There are less code changes than changes in the help docs, as a lot
of docs are produced by some code (e.g. the remote packet usage settings).

gdb/ChangeLog
2019-08-07  Philippe Waroquiers  <philippe.waroquiers@skynet.be>

	* cli/cli-decode.h (print_doc_line): Add for_value_prefix argument.
	* cli/cli-decode.c (print_doc_line): Likewise.  It now prints
	the full first line, except when FOR_VALUE_PREFIX.  In this case,
	the trailing '.' is not output, and the first character is uppercased.
	(print_help_for_command): Update call to print_doc_line.
	(print_doc_of_command): Likewise.
	* cli/cli-setshow.c (deprecated_show_value_hack): Likewise.
	* cli/cli-option.c (append_indented_doc): Do not append newline.
	(build_help_option): Append newline after first appended_indented_doc
	only if a second call is done.
	(build_help): Append 2 new lines before each option, except the first
	one.
	* compile/compile.c (_initialize_compile): Add new lines after
	%OPTIONS%, when not at the end of the help.
	Change help doc or code
	producing the help doc to respect the invariants.
	* maint-test-options.c (_initialize_maint_test_options): Likewise.
	Also removed the new line after 'Options:', as all other commands
	do not put an empty line between 'Options:' and the first option.
	* printcmd.c (_initialize_printcmd): Likewise.
	* stack.c (_initialize_stack): Likewise.
	* interps.c (interpreter_exec_cmd): Fix "Usage:" line that was
	incorrectly telling COMMAND is optional.
	* ada-lang.c (_initialize_ada_language): Change help doc or code
	producing the help doc to respect the invariants.
	* ada-tasks.c (_initialize_ada_tasks): Likewise.
	* breakpoint.c (_initialize_breakpoint): Likewise.
	* cli/cli-cmds.c (_initialize_cli_cmds): Likewise.
	* cli/cli-logging.c (_initialize_cli_logging): Likewise.
	* cli/cli-setshow.c (_initialize_cli_setshow): Likewise.
	* cli/cli-style.c (cli_style_option::add_setshow_commands,
	_initialize_cli_style): Likewise.
	* corelow.c (core_target_info): Likewise.
	* dwarf-index-cache.c (_initialize_index_cache): Likewise.
	* dwarf2read.c (_initialize_dwarf2_read): Likewise.
	* filesystem.c (_initialize_filesystem): Likewise.
	* frame.c (_initialize_frame): Likewise.
	* gnu-nat.c (add_task_commands): Likewise.
	* infcall.c (_initialize_infcall): Likewise.
	* infcmd.c (_initialize_infcmd): Likewise.
	* interps.c (_initialize_interpreter): Likewise.
	* language.c (_initialize_language): Likewise.
	* linux-fork.c (_initialize_linux_fork): Likewise.
	* maint-test-settings.c (_initialize_maint_test_settings): Likewise.
	* maint.c (_initialize_maint_cmds): Likewise.
	* memattr.c (_initialize_mem): Likewise.
	* printcmd.c (_initialize_printcmd): Likewise.
	* python/lib/gdb/function/strfns.py (_MemEq, _StrLen, _StrEq,
	_RegEx): Likewise.
	* ravenscar-thread.c (_initialize_ravenscar): Likewise.
	* record-btrace.c (_initialize_record_btrace): Likewise.
	* record-full.c (_initialize_record_full): Likewise.
	* record.c (_initialize_record): Likewise.
	* regcache-dump.c (_initialize_regcache_dump): Likewise.
	* regcache.c (_initialize_regcache): Likewise.
	* remote.c (add_packet_config_cmd, init_remote_threadtests,
	_initialize_remote): Likewise.
	* ser-tcp.c (_initialize_ser_tcp): Likewise.
	* serial.c (_initialize_serial): Likewise.
	* skip.c (_initialize_step_skip): Likewise.
	* source.c (_initialize_source): Likewise.
	* stack.c (_initialize_stack): Likewise.
	* symfile.c (_initialize_symfile): Likewise.
	* symtab.c (_initialize_symtab): Likewise.
	* target-descriptions.c (_initialize_target_descriptions): Likewise.
	* top.c (init_main): Likewise.
	* tracefile-tfile.c (tfile_target_info): Likewise.
	* tracepoint.c (_initialize_tracepoint): Likewise.
	* tui/tui-win.c (_initialize_tui_win): Likewise.
	* utils.c (add_internal_problem_command): Likewise.
	* valprint.c (value_print_option_defs): Likewise.

gdb/testsuite/ChangeLog
2019-08-07  Philippe Waroquiers  <philippe.waroquiers@skynet.be>

	* gdb.base/style.exp: Update tests for help doc new invariants.
	* gdb.base/help.exp: Likewise.
2019-08-07 00:04:33 +02:00

376 lines
10 KiB
C

/* CLI colorizing
Copyright (C) 2018-2019 Free Software Foundation, Inc.
This file is part of GDB.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
#include "defs.h"
#include "cli/cli-cmds.h"
#include "cli/cli-style.h"
#include "source-cache.h"
#include "observable.h"
/* True if styling is enabled. */
#if defined (__MSDOS__) || defined (__CYGWIN__)
int cli_styling = 0;
#else
int cli_styling = 1;
#endif
/* True if source styling is enabled. Note that this is only
consulted when cli_styling is true. */
int source_styling = 1;
/* Name of colors; must correspond to ui_file_style::basic_color. */
static const char * const cli_colors[] = {
"none",
"black",
"red",
"green",
"yellow",
"blue",
"magenta",
"cyan",
"white",
nullptr
};
/* Names of intensities; must correspond to
ui_file_style::intensity. */
static const char * const cli_intensities[] = {
"normal",
"bold",
"dim",
nullptr
};
/* See cli-style.h. */
cli_style_option file_name_style ("filename", ui_file_style::GREEN);
/* See cli-style.h. */
cli_style_option function_name_style ("function", ui_file_style::YELLOW);
/* See cli-style.h. */
cli_style_option variable_name_style ("variable", ui_file_style::CYAN);
/* See cli-style.h. */
cli_style_option address_style ("address", ui_file_style::BLUE);
/* See cli-style.h. */
cli_style_option highlight_style ("highlight", ui_file_style::RED);
/* See cli-style.h. */
cli_style_option title_style ("title", ui_file_style::BOLD);
/* See cli-style.h. */
cli_style_option::cli_style_option (const char *name,
ui_file_style::basic_color fg)
: m_name (name),
m_foreground (cli_colors[fg - ui_file_style::NONE]),
m_background (cli_colors[0]),
m_intensity (cli_intensities[ui_file_style::NORMAL])
{
}
/* See cli-style.h. */
cli_style_option::cli_style_option (const char *name,
ui_file_style::intensity i)
: m_name (name),
m_foreground (cli_colors[0]),
m_background (cli_colors[0]),
m_intensity (cli_intensities[i])
{
}
/* Return the color number corresponding to COLOR. */
static int
color_number (const char *color)
{
for (int i = 0; i < ARRAY_SIZE (cli_colors); ++i)
{
if (color == cli_colors[i])
return i - 1;
}
gdb_assert_not_reached ("color not found");
}
/* See cli-style.h. */
ui_file_style
cli_style_option::style () const
{
int fg = color_number (m_foreground);
int bg = color_number (m_background);
ui_file_style::intensity intensity = ui_file_style::NORMAL;
for (int i = 0; i < ARRAY_SIZE (cli_intensities); ++i)
{
if (m_intensity == cli_intensities[i])
{
intensity = (ui_file_style::intensity) i;
break;
}
}
return ui_file_style (fg, bg, intensity);
}
/* Implements the cli_style_option::do_show_* functions.
WHAT and VALUE are the property and value to show.
The style for which WHAT is shown is retrieved from CMD context. */
static void
do_show (const char *what, struct ui_file *file,
struct cmd_list_element *cmd,
const char *value)
{
cli_style_option *cso = (cli_style_option *) get_cmd_context (cmd);
fputs_filtered (_("The "), file);
fprintf_styled (file, cso->style (), _("\"%s\" style"), cso->name ());
fprintf_filtered (file, _(" %s is: %s\n"), what, value);
}
/* See cli-style.h. */
void
cli_style_option::do_show_foreground (struct ui_file *file, int from_tty,
struct cmd_list_element *cmd,
const char *value)
{
do_show (_("foreground color"), file, cmd, value);
}
/* See cli-style.h. */
void
cli_style_option::do_show_background (struct ui_file *file, int from_tty,
struct cmd_list_element *cmd,
const char *value)
{
do_show (_("background color"), file, cmd, value);
}
/* See cli-style.h. */
void
cli_style_option::do_show_intensity (struct ui_file *file, int from_tty,
struct cmd_list_element *cmd,
const char *value)
{
do_show (_("display intensity"), file, cmd, value);
}
/* See cli-style.h. */
void
cli_style_option::add_setshow_commands (enum command_class theclass,
const char *prefix_doc,
struct cmd_list_element **set_list,
void (*do_set) (const char *args,
int from_tty),
struct cmd_list_element **show_list,
void (*do_show) (const char *args,
int from_tty))
{
m_set_prefix = std::string ("set style ") + m_name + " ";
m_show_prefix = std::string ("show style ") + m_name + " ";
add_prefix_cmd (m_name, no_class, do_set, prefix_doc, &m_set_list,
m_set_prefix.c_str (), 0, set_list);
add_prefix_cmd (m_name, no_class, do_show, prefix_doc, &m_show_list,
m_show_prefix.c_str (), 0, show_list);
add_setshow_enum_cmd ("foreground", theclass, cli_colors,
&m_foreground,
_("Set the foreground color for this property."),
_("Show the foreground color for this property."),
nullptr,
nullptr,
do_show_foreground,
&m_set_list, &m_show_list, (void *) this);
add_setshow_enum_cmd ("background", theclass, cli_colors,
&m_background,
_("Set the background color for this property."),
_("Show the background color for this property."),
nullptr,
nullptr,
do_show_background,
&m_set_list, &m_show_list, (void *) this);
add_setshow_enum_cmd ("intensity", theclass, cli_intensities,
&m_intensity,
_("Set the display intensity for this property."),
_("Show the display intensity for this property."),
nullptr,
nullptr,
do_show_intensity,
&m_set_list, &m_show_list, (void *) this);
}
static cmd_list_element *style_set_list;
static cmd_list_element *style_show_list;
static void
set_style (const char *arg, int from_tty)
{
printf_unfiltered (_("\"set style\" must be followed "
"by an appropriate subcommand.\n"));
help_list (style_set_list, "set style ", all_commands, gdb_stdout);
}
static void
show_style (const char *arg, int from_tty)
{
cmd_show_list (style_show_list, from_tty, "");
}
static void
set_style_enabled (const char *args, int from_tty, struct cmd_list_element *c)
{
g_source_cache.clear ();
gdb::observers::source_styling_changed.notify ();
}
static void
show_style_enabled (struct ui_file *file, int from_tty,
struct cmd_list_element *c, const char *value)
{
if (cli_styling)
fprintf_filtered (file, _("CLI output styling is enabled.\n"));
else
fprintf_filtered (file, _("CLI output styling is disabled.\n"));
}
static void
show_style_sources (struct ui_file *file, int from_tty,
struct cmd_list_element *c, const char *value)
{
if (source_styling)
fprintf_filtered (file, _("Source code styling is enabled.\n"));
else
fprintf_filtered (file, _("Source code styling is disabled.\n"));
}
/* Builds the "set style NAME " prefix. */
static std::string
set_style_name (const char *name)
{
std::string result ("set style ");
result += name;
result += " ";
return result;
}
void
_initialize_cli_style ()
{
add_prefix_cmd ("style", no_class, set_style, _("\
Style-specific settings.\n\
Configure various style-related variables, such as colors"),
&style_set_list, "set style ", 0, &setlist);
add_prefix_cmd ("style", no_class, show_style, _("\
Style-specific settings.\n\
Configure various style-related variables, such as colors"),
&style_show_list, "show style ", 0, &showlist);
add_setshow_boolean_cmd ("enabled", no_class, &cli_styling, _("\
Set whether CLI styling is enabled."), _("\
Show whether CLI is enabled."), _("\
If enabled, output to the terminal is styled."),
set_style_enabled, show_style_enabled,
&style_set_list, &style_show_list);
add_setshow_boolean_cmd ("sources", no_class, &source_styling, _("\
Set whether source code styling is enabled."), _("\
Show whether source code styling is enabled."), _("\
If enabled, source code is styled.\n"
#ifdef HAVE_SOURCE_HIGHLIGHT
"Note that source styling only works if styling in general is enabled,\n\
see \"show style enabled\"."
#else
"Source highlighting is disabled in this installation of gdb, because\n\
it was not linked against GNU Source Highlight."
#endif
), set_style_enabled, show_style_sources,
&style_set_list, &style_show_list);
#define STYLE_ADD_SETSHOW_COMMANDS(STYLE, PREFIX_DOC) \
STYLE.add_setshow_commands (no_class, PREFIX_DOC, \
&style_set_list, \
[] (const char *args, int from_tty) \
{ \
help_list \
(STYLE.set_list (), \
set_style_name (STYLE.name ()).c_str (), \
all_commands, \
gdb_stdout); \
}, \
&style_show_list, \
[] (const char *args, int from_tty) \
{ \
cmd_show_list \
(STYLE.show_list (), \
from_tty, \
""); \
})
STYLE_ADD_SETSHOW_COMMANDS (file_name_style,
_("\
Filename display styling.\n\
Configure filename colors and display intensity."));
STYLE_ADD_SETSHOW_COMMANDS (function_name_style,
_("\
Function name display styling.\n\
Configure function name colors and display intensity"));
STYLE_ADD_SETSHOW_COMMANDS (variable_name_style,
_("\
Variable name display styling.\n\
Configure variable name colors and display intensity"));
STYLE_ADD_SETSHOW_COMMANDS (address_style,
_("\
Address display styling.\n\
Configure address colors and display intensity"));
STYLE_ADD_SETSHOW_COMMANDS (title_style,
_("\
Title display styling.\n\
Configure title colors and display intensity\n\
Some commands (such as \"apropos -v REGEXP\") use the title style to improve\n\
readability."));
STYLE_ADD_SETSHOW_COMMANDS (highlight_style,
_("\
Highlight display styling.\n\
Configure highlight colors and display intensity\n\
Some commands use the highlight style to draw the attention to a part\n\
of their output."));
}