Enable styling by default on Cygwin
[deliverable/binutils-gdb.git] / gdb / cli / cli-style.c
index fc91504d1f8f9b0e5e195e014d9084dc0ce164dd..f3d98ae4091008cf524ed7085e7c31e204d8cf72 100644 (file)
@@ -1,6 +1,6 @@
 /* CLI colorizing
 
-   Copyright (C) 2018-2019 Free Software Foundation, Inc.
+   Copyright (C) 2018-2020 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
 
 /* True if styling is enabled.  */
 
-#if defined (__MSDOS__) || defined (__CYGWIN__)
-int cli_styling = 0;
+#if defined (__MSDOS__)
+bool cli_styling = false;
 #else
-int cli_styling = 1;
+bool cli_styling = true;
 #endif
 
+/* True if source styling is enabled.  Note that this is only
+   consulted when cli_styling is true.  */
+
+bool source_styling = true;
+
 /* Name of colors; must correspond to ui_file_style::basic_color.  */
 static const char * const cli_colors[] = {
   "none",
@@ -56,29 +61,65 @@ static const char * const cli_intensities[] = {
 
 /* See cli-style.h.  */
 
-cli_style_option file_name_style (ui_file_style::GREEN);
+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 function_name_style (ui_file_style::YELLOW);
+cli_style_option tui_border_style ("tui-border", ui_file_style::CYAN);
 
 /* See cli-style.h.  */
 
-cli_style_option variable_name_style (ui_file_style::CYAN);
+cli_style_option tui_active_border_style ("tui-active-border",
+                                         ui_file_style::CYAN);
 
 /* See cli-style.h.  */
 
-cli_style_option address_style (ui_file_style::BLUE);
+cli_style_option metadata_style ("metadata", ui_file_style::DIM);
 
 /* See cli-style.h.  */
 
-cli_style_option::cli_style_option (ui_file_style::basic_color fg)
-  : m_foreground (cli_colors[fg - ui_file_style::NONE]),
+cli_style_option::cli_style_option (const char *name,
+                                   ui_file_style::basic_color fg)
+  : changed (name),
+    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)
+  : changed (name),
+    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
@@ -115,14 +156,37 @@ cli_style_option::style () const
 
 /* See cli-style.h.  */
 
+void
+cli_style_option::do_set_value (const char *ignore, int from_tty,
+                               struct cmd_list_element *cmd)
+{
+  cli_style_option *cso = (cli_style_option *) get_cmd_context (cmd);
+  cso->changed.notify ();
+}
+
+/* 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)
 {
-  const char *name = (const char *) get_cmd_context (cmd);
-  fprintf_filtered (file, _("The \"%s\" foreground color is: %s\n"),
-                   name, value);
+  do_show (_("foreground color"), file, cmd, value);
 }
 
 /* See cli-style.h.  */
@@ -132,9 +196,7 @@ cli_style_option::do_show_background (struct ui_file *file, int from_tty,
                                      struct cmd_list_element *cmd,
                                      const char *value)
 {
-  const char *name = (const char *) get_cmd_context (cmd);
-  fprintf_filtered (file, _("The \"%s\" background color is: %s\n"),
-                   name, value);
+  do_show (_("background color"), file, cmd, value);
 }
 
 /* See cli-style.h.  */
@@ -144,56 +206,55 @@ cli_style_option::do_show_intensity (struct ui_file *file, int from_tty,
                                     struct cmd_list_element *cmd,
                                     const char *value)
 {
-  const char *name = (const char *) get_cmd_context (cmd);
-  fprintf_filtered (file, _("The \"%s\" display intensity is: %s\n"),
-                   name, value);
+  do_show (_("display intensity"), file, cmd, value);
 }
 
 /* See cli-style.h.  */
 
 void
-cli_style_option::add_setshow_commands (const char *name,
-                                       enum command_class theclass,
+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))
+                                                        int from_tty),
+                                       bool skip_intensity)
 {
-  m_set_prefix = std::string ("set style ") + name + " ";
-  m_show_prefix = std::string ("show style ") + name + " ";
+  m_set_prefix = std::string ("set style ") + m_name + " ";
+  m_show_prefix = std::string ("show style ") + m_name + " ";
 
-  add_prefix_cmd (name, no_class, do_set, prefix_doc, &m_set_list,
+  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 (name, no_class, do_show, prefix_doc, &m_show_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,
+                       _("Set the foreground color for this property."),
+                       _("Show the foreground color for this property."),
                        nullptr,
+                       do_set_value,
                        do_show_foreground,
-                       &m_set_list, &m_show_list, (void *) name);
+                       &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,
+                       _("Set the background color for this property."),
+                       _("Show the background color for this property."),
                        nullptr,
+                       do_set_value,
                        do_show_background,
-                       &m_set_list, &m_show_list, (void *) name);
-  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 *) name);
+                       &m_set_list, &m_show_list, (void *) this);
+  if (!skip_intensity)
+    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,
+                         do_set_value,
+                         do_show_intensity,
+                         &m_set_list, &m_show_list, (void *) this);
 }
 
 static cmd_list_element *style_set_list;
@@ -230,15 +291,37 @@ show_style_enabled (struct ui_file *file, int from_tty,
     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\
+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\
+Style-specific settings.\n\
 Configure various style-related variables, such as colors"),
                  &style_show_list, "show style ", 0, &showlist);
 
@@ -249,14 +332,28 @@ If enabled, output to the terminal is styled."),
                           set_style_enabled, show_style_enabled,
                           &style_set_list, &style_show_list);
 
-#define STYLE_ADD_SETSHOW_COMMANDS(STYLE, NAME, PREFIX_DOC)      \
-  STYLE.add_setshow_commands (NAME, no_class, PREFIX_DOC,              \
+  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, SKIP)            \
+  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 " ",               \
+                                  set_style_name (STYLE.name ()).c_str (), \
                                   all_commands,                        \
                                   gdb_stdout);                         \
                              },                                        \
@@ -267,25 +364,60 @@ If enabled, output to the terminal is styled."),
                                  (STYLE.show_list (),                  \
                                   from_tty,                            \
                                   "");                                 \
-                             })
+                             }, SKIP)
+
+  STYLE_ADD_SETSHOW_COMMANDS (file_name_style,
+                             _("\
+Filename display styling.\n\
+Configure filename colors and display intensity."), false);
+
+  STYLE_ADD_SETSHOW_COMMANDS (function_name_style,
+                             _("\
+Function name display styling.\n\
+Configure function name colors and display intensity"), false);
+
+  STYLE_ADD_SETSHOW_COMMANDS (variable_name_style,
+                             _("\
+Variable name display styling.\n\
+Configure variable name colors and display intensity"), false);
+
+  STYLE_ADD_SETSHOW_COMMANDS (address_style,
+                             _("\
+Address display styling.\n\
+Configure address colors and display intensity"), false);
+
+  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."), false);
 
-  STYLE_ADD_SETSHOW_COMMANDS (file_name_style, "filename",
+  STYLE_ADD_SETSHOW_COMMANDS (highlight_style,
                              _("\
-Filename display styling\n\
-Configure filename colors and display intensity."));
+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."), false);
 
-  STYLE_ADD_SETSHOW_COMMANDS (function_name_style, "function",
+  STYLE_ADD_SETSHOW_COMMANDS (metadata_style,
                              _("\
-Function name display styling\n\
-Configure function name colors and display intensity"));
+Metadata display styling.\n\
+Configure metadata colors and display intensity\n\
+The \"metadata\" style is used when GDB displays information about\n\
+your data, for example \"<unavailable>\""), false);
 
-  STYLE_ADD_SETSHOW_COMMANDS (variable_name_style, "variable",
+  STYLE_ADD_SETSHOW_COMMANDS (tui_border_style,
                              _("\
-Variable name display styling\n\
-Configure variable name colors and display intensity"));
+TUI border display styling.\n\
+Configure TUI border colors\n\
+The \"tui-border\" style is used when GDB displays the border of a\n\
+TUI window that does not have the focus."), true);
 
-  STYLE_ADD_SETSHOW_COMMANDS (address_style, "address",
+  STYLE_ADD_SETSHOW_COMMANDS (tui_active_border_style,
                              _("\
-Address display styling\n\
-Configure address colors and display intensity"));
+TUI active border display styling.\n\
+Configure TUI active border colors\n\
+The \"tui-active-border\" style is used when GDB displays the border of a\n\
+TUI window that does have the focus."), true);
 }
This page took 0.03759 seconds and 4 git commands to generate.