From patchwork Wed Nov 28 00:14:25 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 30342 Received: (qmail 27273 invoked by alias); 28 Nov 2018 00:14:44 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 27148 invoked by uid 89); 28 Nov 2018 00:14:43 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=formatted, ANSI, pressing, U*tom X-HELO: gateway32.websitewelcome.com Received: from gateway32.websitewelcome.com (HELO gateway32.websitewelcome.com) (192.185.145.102) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 28 Nov 2018 00:14:40 +0000 Received: from cm17.websitewelcome.com (cm17.websitewelcome.com [100.42.49.20]) by gateway32.websitewelcome.com (Postfix) with ESMTP id 66EA9CE8291 for ; Tue, 27 Nov 2018 18:14:39 -0600 (CST) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id RnV1gAfwGPvAdRnV1gqWEu; Tue, 27 Nov 2018 18:14:39 -0600 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=1YFHv8baecIlYtg5mWbJMATF+CP87RXJnQIjcJG6X1U=; b=S7hRxJGyS410x7mOgAgNJTKZxi jucr30nxUl66H+fqro7D2H7b6NHnFBunt82ByFUbC8el2RyVvcCbTYaqP7hNux/UYRNk8A6ACB/5T uxBuhdUgPCUDzIaFfII5YStkL; Received: from 97-122-190-66.hlrn.qwest.net ([97.122.190.66]:33804 helo=bapiya.Home) by box5379.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.91) (envelope-from ) id 1gRnV1-004MMp-6Y; Tue, 27 Nov 2018 18:14:39 -0600 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH 06/16] Reset terminal styles Date: Tue, 27 Nov 2018 17:14:25 -0700 Message-Id: <20181128001435.12703-7-tom@tromey.com> In-Reply-To: <20181128001435.12703-1-tom@tromey.com> References: <20181128001435.12703-1-tom@tromey.com> This adds a function that can be used to reset terminal styles, regardless of what style the low-levle output routines currently think is applied. This is used to make "echo" and "printf" work properly when emitting ANSI terminal escapes -- now gdb will reset the style at the end of the command. gdb/ChangeLog 2018-11-27 Tom Tromey * utils.h (reset_terminal_style): Declare. * utils.c (can_emit_style_escape): New function. (set_output_style): Use it. (reset_terminal_style): New function. * printcmd.c (printf_command): Call reset_terminal_style. * cli/cli-cmds.c (echo_command): Call reset_terminal_style. --- gdb/ChangeLog | 9 +++++++++ gdb/cli/cli-cmds.c | 2 ++ gdb/printcmd.c | 2 ++ gdb/utils.c | 37 +++++++++++++++++++++++++++++++------ gdb/utils.h | 4 ++++ 5 files changed, 48 insertions(+), 6 deletions(-) diff --git a/gdb/cli/cli-cmds.c b/gdb/cli/cli-cmds.c index 135f550b80..12ac74c7e9 100644 --- a/gdb/cli/cli-cmds.c +++ b/gdb/cli/cli-cmds.c @@ -689,6 +689,8 @@ echo_command (const char *text, int from_tty) printf_filtered ("%c", c); } + reset_terminal_style (gdb_stdout); + /* Force this output to appear now. */ wrap_here (""); gdb_flush (gdb_stdout); diff --git a/gdb/printcmd.c b/gdb/printcmd.c index 8c999188d7..79c3d2d2ff 100644 --- a/gdb/printcmd.c +++ b/gdb/printcmd.c @@ -2609,6 +2609,8 @@ static void printf_command (const char *arg, int from_tty) { ui_printf (arg, gdb_stdout); + reset_terminal_style (gdb_stdout); + wrap_here (""); gdb_flush (gdb_stdout); } diff --git a/gdb/utils.c b/gdb/utils.c index 69c9e76576..85b0fb14e3 100644 --- a/gdb/utils.c +++ b/gdb/utils.c @@ -1444,25 +1444,50 @@ emit_style_escape (const ui_file_style &style) wrap_buffer.append (style.to_ansi ()); } -/* Set the current output style. This will affect future uses of the - _filtered output functions. */ +/* Return true if ANSI escapes can be used on STREAM. */ -static void -set_output_style (struct ui_file *stream, const ui_file_style &style) +static bool +can_emit_style_escape (struct ui_file *stream) { if (stream != gdb_stdout || !cli_styling - || style == desired_style || !ui_file_isatty (stream)) - return; + return false; const char *term = getenv ("TERM"); if (term == nullptr || !strcmp (term, "dumb")) + return false; + return true; +} + +/* Set the current output style. This will affect future uses of the + _filtered output functions. */ + +static void +set_output_style (struct ui_file *stream, const ui_file_style &style) +{ + if (!can_emit_style_escape (stream) + || style == desired_style) return; desired_style = style; emit_style_escape (style); } +/* See utils.h. */ + +void +reset_terminal_style (struct ui_file *stream) +{ + if (can_emit_style_escape (stream)) + { + /* Force the setting, regardless of what we think the setting + might already be. */ + desired_style = ui_file_style (); + applied_style = desired_style; + wrap_buffer.append (desired_style.to_ansi ()); + } +} + /* Wait, so the user can read what's on the screen. Prompt the user to continue by pressing RETURN. 'q' is also provided because telling users what to do in the prompt is more user-friendly than diff --git a/gdb/utils.h b/gdb/utils.h index 9872a15fd7..1f09ec2d47 100644 --- a/gdb/utils.h +++ b/gdb/utils.h @@ -439,6 +439,10 @@ extern void fputs_styled (const char *linebuffer, const ui_file_style &style, struct ui_file *stream); +/* Reset the terminal style to the default, if needed. */ + +extern void reset_terminal_style (struct ui_file *stream); + /* Display the host ADDR on STREAM formatted as ``0x%x''. */ extern void gdb_print_host_address_1 (const void *addr, struct ui_file *stream);