From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gateway30.websitewelcome.com (gateway30.websitewelcome.com [50.116.125.1]) by sourceware.org (Postfix) with ESMTPS id 1341C395446E for ; Tue, 23 Jun 2020 13:20:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 1341C395446E Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=tromey.com Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=tom@tromey.com Received: from cm13.websitewelcome.com (cm13.websitewelcome.com [100.42.49.6]) by gateway30.websitewelcome.com (Postfix) with ESMTP id 6BCE15C292 for ; Tue, 23 Jun 2020 08:20:10 -0500 (CDT) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id niqQj0q3ZwgQAniqQjXG9N; Tue, 23 Jun 2020 08:20:10 -0500 X-Authority-Reason: nr=8 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Sender:Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=zyGVVCVlmX5yS0pGwlRfX0ZW9W4g8QVuqX6g0rm2dOY=; b=OP2eLUl5mAgUYaJzQzBGff0T2N LXlUAWG2RSap3/xkBxyE8PzSCLFCC00Emm62ZrIV5weDh+nbdnRg5OxAgnq2E5VgxQOZ6ldwln67m UqQAIQn0Ja73gG9alhLKjpk/Y; Received: from 174-16-104-48.hlrn.qwest.net ([174.16.104.48]:45100 helo=bapiya.Home) by box5379.bluehost.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1jniqQ-002fzZ-2a; Tue, 23 Jun 2020 07:20:10 -0600 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH v2 6/7] Let the user control the startup style Date: Tue, 23 Jun 2020 07:20:05 -0600 Message-Id: <20200623132006.15863-7-tom@tromey.com> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20200623132006.15863-1-tom@tromey.com> References: <20200623132006.15863-1-tom@tromey.com> X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - box5379.bluehost.com X-AntiAbuse: Original Domain - sourceware.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - tromey.com X-BWhitelist: no X-Source-IP: 174.16.104.48 X-Source-L: No X-Exim-ID: 1jniqQ-002fzZ-2a X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 174-16-104-48.hlrn.qwest.net (bapiya.Home) [174.16.104.48]:45100 X-Source-Auth: tom+tromey.com X-Email-Count: 7 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-Spam-Status: No, score=-3037.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_SHORT, RCVD_IN_ABUSEAT, RCVD_IN_BARRACUDACENTRAL, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 23 Jun 2020 13:20:13 -0000 Some users find the startup text highlighting to be distracting. This patch provides a way to change this, building on the startup file infrastructure that was added earlier. gdb/ChangeLog 2020-06-22 Tom Tromey * tips: Add a tip. * NEWS: Add entry. * top.c (startup_style): Remove. (print_tip, print_gdb_version): Update. * cli/cli-style.h (class cli_style_option) : Add intensity parameter. : Declare new method. (startup_style): Declare. * cli/cli-style.c (startup_style): New global. (cli_style_option): Add intensity parameter. (cli_style_option::write): New method. (_initialize_cli_style): Register new style and callbacks. gdb/doc/ChangeLog 2020-06-22 Tom Tromey * gdb.texinfo (Output Styling): Document "set style startup" commands. gdb/testsuite/ChangeLog 2020-06-22 Tom Tromey * gdb.base/persist.exp: New file. --- gdb/ChangeLog | 15 +++++++ gdb/NEWS | 7 ++++ gdb/cli/cli-style.c | 36 ++++++++++++++++- gdb/cli/cli-style.h | 9 ++++- gdb/doc/ChangeLog | 5 +++ gdb/doc/gdb.texinfo | 15 +++++++ gdb/testsuite/ChangeLog | 4 ++ gdb/testsuite/gdb.base/persist.exp | 64 ++++++++++++++++++++++++++++++ gdb/tips | 3 ++ gdb/top.c | 12 +----- 10 files changed, 157 insertions(+), 13 deletions(-) create mode 100644 gdb/testsuite/gdb.base/persist.exp diff --git a/gdb/NEWS b/gdb/NEWS index e977630c445..8f474c51bf4 100644 --- a/gdb/NEWS +++ b/gdb/NEWS @@ -80,6 +80,13 @@ show exec-file-mismatch -- Show exec-file-mismatch handling (ask|warn|off). executable file; if 'warn', just display a warning; if 'off', don't attempt to detect a mismatch. +set style startup foreground COLOR +set style startup background COLOR +set style startup intensity VALUE + Control the styling of startup text. This saves the setting into + a special configuration file, so that it can be read during startup + and applied. + tui new-layout NAME WINDOW WEIGHT [WINDOW WEIGHT]... Define a new TUI layout, specifying its name and the windows that will be displayed. diff --git a/gdb/cli/cli-style.c b/gdb/cli/cli-style.c index a0c3cc51801..8486d22ecd9 100644 --- a/gdb/cli/cli-style.c +++ b/gdb/cli/cli-style.c @@ -19,6 +19,7 @@ #include "defs.h" #include "cli/cli-cmds.h" +#include "cli/cli-setshow.h" #include "cli/cli-style.h" #include "source-cache.h" #include "observable.h" @@ -98,13 +99,19 @@ cli_style_option metadata_style ("metadata", ui_file_style::DIM); /* See cli-style.h. */ +cli_style_option startup_style ("startup", ui_file_style::MAGENTA, + ui_file_style::BOLD); + +/* See cli-style.h. */ + cli_style_option::cli_style_option (const char *name, - ui_file_style::basic_color fg) + ui_file_style::basic_color fg, + ui_file_style::intensity intensity) : 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]) + m_intensity (cli_intensities[intensity]) { } @@ -253,6 +260,17 @@ cli_style_option::add_setshow_commands (enum command_class theclass, &m_set_list, &m_show_list, (void *) this); } +void +cli_style_option::write (ui_file *outfile) +{ + fprintf_unfiltered (outfile, "set style %s background %s\n", + m_name, m_background); + fprintf_unfiltered (outfile, "set style %s foreground %s\n", + m_name, m_foreground); + fprintf_unfiltered (outfile, "set style %s intensity %s\n", + m_name, m_intensity); +} + static cmd_list_element *style_set_list; static cmd_list_element *style_show_list; @@ -382,4 +400,18 @@ TUI window that does have the focus."), &style_set_list, &style_show_list, true); + + startup_style.add_setshow_commands (no_class, _("\ +Startup display styling.\n\ +Configure colors used in some startup text."), + &style_set_list, &style_show_list, + false); + /* Ensure that the startup style is written to the startup file. */ + add_startup_writer ([] (ui_file *outfile) + { + startup_style.write (outfile); + }); + /* Arrange to write the startup file whenever a startup style + setting changes. */ + startup_style.changed.attach (write_startup_file); } diff --git a/gdb/cli/cli-style.h b/gdb/cli/cli-style.h index 6422e5296a3..28859f88560 100644 --- a/gdb/cli/cli-style.h +++ b/gdb/cli/cli-style.h @@ -30,7 +30,8 @@ class cli_style_option public: /* Construct a CLI style option with a foreground color. */ - cli_style_option (const char *name, ui_file_style::basic_color fg); + cli_style_option (const char *name, ui_file_style::basic_color fg, + ui_file_style::intensity = ui_file_style::NORMAL); /* Construct a CLI style option with an intensity. */ cli_style_option (const char *name, ui_file_style::intensity i); @@ -56,6 +57,9 @@ class cli_style_option /* Same as SET_LIST but for the show command list. */ struct cmd_list_element *show_list () { return m_show_list; }; + /* Write this style to FILE. */ + void write (ui_file *outfile); + /* This style can be observed for any changes. */ gdb::observers::observable<> changed; @@ -124,6 +128,9 @@ extern cli_style_option tui_border_style; /* The border style of a TUI window that does have the focus. */ extern cli_style_option tui_active_border_style; +/* The style to use for (some) startup text. */ +extern cli_style_option startup_style; + /* True if source styling is enabled. */ extern bool source_styling; diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo index 0a74992fbac..7c3fe7d38a2 100644 --- a/gdb/doc/gdb.texinfo +++ b/gdb/doc/gdb.texinfo @@ -25672,6 +25672,21 @@ Control the styling of addresses. These are managed with the @code{set style address} family of commands. By default, this style's foreground color is blue. +@item startup +Control the styling of some text that is printed at startup. These +are managed with the @code{set style startup} family of commands. By +default, this style's foreground color is magenta and it has bold +intensity. Changing these settings will cause them to automatically +be saved in a special configuration file, which is read by +@value{GDBN} early in its startup. + +The default value for this directory depends on the host platform. On +most systems, the index is cached in the @file{gdb} subdirectory of +the directory pointed to by the @env{XDG_CONFIG_HOME} environment +variable, if it is defined, else in the @file{.config/gdb} subdirectory +of your home directory. However, on some systems, the default may +differ according to local convention. + @item title Control the styling of titles. These are managed with the @code{set style title} family of commands. By default, this style's diff --git a/gdb/testsuite/gdb.base/persist.exp b/gdb/testsuite/gdb.base/persist.exp new file mode 100644 index 00000000000..76a55d558c3 --- /dev/null +++ b/gdb/testsuite/gdb.base/persist.exp @@ -0,0 +1,64 @@ +# Copyright 2020 Free Software Foundation, Inc. + +# 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 . */ + +# This test relies on XDG_CONFIG_HOME, which does not work on all +# platforms; so limit it to Linux native. +if {![istarget "*-*-linux*"]} then { + continue +} +if { [target_info gdb_protocol] != "" } { + continue +} + +# Check that the contents of FILENAME changed and that the contents +# now contain the given command. CONTENTS is the old contents. +# COMMAND is the command to run, and also used to name the test. +# Returns the new contents. +proc require_changed {command filename contents} { + gdb_test_no_output $command + + set fd [open $filename r] + set new [read $fd] + close $fd + + set testname "$command check" + if {$contents == $new || [string first $command $new] == -1} { + fail $testname + } else { + pass $testname + } + + return $new +} + +save_vars { env(XDG_CONFIG_HOME) } { + set dirname [standard_output_file .] + file mkdir $dirname/gdb + set filename $dirname/gdb/startup-commands + + # Create the file as empty. + set fd [open $filename w] + close $fd + + # Current contents. + set contents "" + + setenv XDG_CONFIG_HOME $dirname + clean_restart + + set contents [require_changed "set style startup foreground green" $filename $contents] + set contents [require_changed "set style startup background green" $filename $contents] + set contents [require_changed "set style startup intensity dim" $filename $contents] +} diff --git a/gdb/tips b/gdb/tips index 75957fb853d..a9c89747aa4 100644 --- a/gdb/tips +++ b/gdb/tips @@ -7,3 +7,6 @@ You can use "help news" to see what has changed in GDB. Type "apropos word" to search for commands related to "word". % Type "show configuration" for configuration details. +% +You can use the "set style startup" family of commands to change the +style used for tips. diff --git a/gdb/top.c b/gdb/top.c index 62a2c706031..e86ce4020f3 100644 --- a/gdb/top.c +++ b/gdb/top.c @@ -130,14 +130,6 @@ current_ui_current_uiout_ptr () int inhibit_gdbinit = 0; -/* The style used for informational messages at startup. */ -static ui_file_style startup_style = -{ - ui_file_style::MAGENTA, - ui_file_style::NONE, - ui_file_style::BOLD -}; - /* Flag for whether we want to confirm potentially dangerous operations. Default is yes. */ @@ -1447,7 +1439,7 @@ print_tip (struct ui_file *stream) std::uniform_int_distribution<> distr (0, strings.size () - 1); int index = distr (mt); /* Note that the string will include a newline. */ - fprintf_styled (stream, startup_style, "\n%.*s", + fprintf_styled (stream, startup_style.style (), "\n%.*s", (int) strings[index].size (), strings[index].data ()); } @@ -1462,7 +1454,7 @@ print_gdb_version (struct ui_file *stream, bool interactive) ui_file_style style; if (interactive) - style = startup_style; + style = startup_style.style (); fprintf_styled (stream, style, "GNU gdb %s%s\n", PKGVERSION, version); /* Second line is a copyright notice. */ -- 2.17.2