From patchwork Fri Feb 9 23:56:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 85552 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 83EE33858CDA for ; Fri, 9 Feb 2024 23:57:17 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from omta34.uswest2.a.cloudfilter.net (omta34.uswest2.a.cloudfilter.net [35.89.44.33]) by sourceware.org (Postfix) with ESMTPS id 895393858D1E for ; Fri, 9 Feb 2024 23:56:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 895393858D1E Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=tromey.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=tromey.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 895393858D1E Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=35.89.44.33 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1707523014; cv=none; b=Ge82ghQfBYb5EhwGQCUEjc1tqIxD+0hBhrJckE+CEDldTfha2Pvi1ylWxt62I0s+xLA+xThmk7B40JX56y8D9yM48u0DPzURK8l37D6mIkAgQFL3a3qc5sM9oY//pUBtnBsN41sNgKwKY8+CTV3NW0kClwaxlbII76XYkLBPrwU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1707523014; c=relaxed/simple; bh=yAM6/h/WFqvTxpnMFdIxw06Y1onJ676Ug0KlJdjHPpg=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=BMe4aPS/abwDP7Ri4D1oiAXa9YrJpruLQIJjR+SclL3pdwhIbyBw76GgELZmtjEeKfgZR2WjS0SC7vnRtEXSwtvuGhzReSrc92L2cWxoOEWe785+++tq5Go1F0dfly6HBYL985AtVrNFYd8DRL2soM9AHXDO5L251CG3lcQ9l20= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from eig-obgw-5002a.ext.cloudfilter.net ([10.0.29.215]) by cmsmtp with ESMTPS id Ya9Srz7wYpUFLYajirgREt; Fri, 09 Feb 2024 23:56:50 +0000 Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with ESMTPS id YajhrwJwnc6jSYajhrQF3R; Fri, 09 Feb 2024 23:56:49 +0000 X-Authority-Analysis: v=2.4 cv=bafIU/PB c=1 sm=1 tr=0 ts=65c6bbc1 a=ApxJNpeYhEAb1aAlGBBbmA==:117 a=ApxJNpeYhEAb1aAlGBBbmA==:17 a=k7vzHIieQBIA:10 a=Qbun_eYptAEA:10 a=CCpqsmhAAAAA:8 a=3yqXjO8_1e9H4qz5Sj0A:9 a=ul9cdbp4aOFLsgKbc677:22 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=Content-Transfer-Encoding:MIME-Version:Message-ID:Date:Subject: Cc:To:From:Sender:Reply-To:Content-Type:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: In-Reply-To:References:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=N4F0Wb89ek139CVBhINtQacaCMAZ3c3JMtqrT22SQUQ=; b=ra87T3fh60VEVyxjcQnym/R4d0 GlHp80hXLx4CQK/KTAUsZEUuvutpZ5uW312DeucQjg2WhxjzIHB9DMdMipHZQcFy9d4UUoEpqCD/M Fga/TOb7kADZDg/SaetzjFMuK; Received: from [161.98.8.3] (port=49066 helo=prentzel.ci.boulder.co.us) by box5379.bluehost.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96.2) (envelope-from ) id 1rYajh-000NLm-0Z; Fri, 09 Feb 2024 16:56:49 -0700 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH] Fix TUI text centering Date: Fri, 9 Feb 2024 16:56:47 -0700 Message-ID: <20240209235647.2163118-1-tom@tromey.com> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 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: 161.98.8.3 X-Source-L: No X-Exim-ID: 1rYajh-000NLm-0Z X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: (prentzel.ci.boulder.co.us) [161.98.8.3]:49066 X-Source-Auth: tom+tromey.com X-Email-Count: 1 X-Org: HG=bhshared;ORG=bluehost; X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-CMAE-Envelope: MS4xfFinEaUSE0+zei7oSc4GiB0JVmRoWFZqAIjYjqbJgLIljLnX10kvUjkqABActvBz5jBc6jleFJ4En9DsGpdGB0r3IU6gQU4B5887E5Z8g9j3HqK4+wIL bUTV/jmroBTcVhXUAKlwGzieIXhTDrX8i2kGxs28oezmwu9aRqEj8WZ+yET3NM4b9UxwsJO1FrQJf/9BdBqG1/rSStBYtloXqvI= X-Spam-Status: No, score=-3022.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_SHORT, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org In a couple of spots, the TUI tries to center some text in the window. Andrew noticed that the calculation is done strangely and the text ends up somewhat to the left of center. This patch fixes the problem. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31355 --- gdb/testsuite/gdb.tui/regs.exp | 5 ++++- gdb/tui/tui-data.c | 20 +++++++++++++++----- gdb/tui/tui-data.h | 6 +++--- gdb/tui/tui-regs.c | 12 +----------- gdb/tui/tui-winsource.c | 20 +++----------------- 5 files changed, 26 insertions(+), 37 deletions(-) diff --git a/gdb/testsuite/gdb.tui/regs.exp b/gdb/testsuite/gdb.tui/regs.exp index ea78b57d1a7..183c2ea0f03 100644 --- a/gdb/testsuite/gdb.tui/regs.exp +++ b/gdb/testsuite/gdb.tui/regs.exp @@ -46,7 +46,10 @@ Term::check_box "source box in regs layout" 0 7 80 8 # The current frame is main, check that registers are available. set re_reg_vals_unavailable \ - [string_to_regexp {[ Register Values Unavailable ]}] + [string_to_regexp \ + [string cat \ + [string repeat " " 23] \ + {[ Register Values Unavailable ]}]] gdb_assert \ { ![Term::check_region_contents_p 0 0 80 8 $re_reg_vals_unavailable] } \ "Register values available" diff --git a/gdb/tui/tui-data.c b/gdb/tui/tui-data.c index 38a87a2a6e9..03395d2df09 100644 --- a/gdb/tui/tui-data.c +++ b/gdb/tui/tui-data.c @@ -169,13 +169,23 @@ tui_win_info::set_title (std::string &&new_title) /* See tui-data.h. */ void -tui_win_info::display_string (int y, int x, const char *str) const +tui_win_info::center_string (const char *str) { - int n = width - box_width () - x; - if (n <= 0) - return; + werase (handle.get ()); + check_and_display_highlight_if_needed (); + + int avail_width = width - box_size (); + int len = strlen (str); + + int x_pos = box_width (); + if (len < avail_width) + x_pos += (avail_width - len) / 2; + + int n = avail_width - x_pos; + gdb_assert (n > 0); - mvwaddnstr (handle.get (), y, x, str, n); + mvwaddnstr (handle.get (), height / 2, x_pos, str, n); + refresh_window (); } /* See tui-data.h. */ diff --git a/gdb/tui/tui-data.h b/gdb/tui/tui-data.h index 1714f5ae455..4a44a0bc6e8 100644 --- a/gdb/tui/tui-data.h +++ b/gdb/tui/tui-data.h @@ -167,9 +167,9 @@ struct tui_win_info const std::string &title () const { return m_title; } - /* Display string STR in the window at position (Y,X), abbreviated if - necessary. */ - void display_string (int y, int x, const char *str) const; + /* Clear the window, maybe draw the boarder, and then display string + STR centered in the window, abbreviated if necessary. */ + void center_string (const char *str); /* Display string STR in the window at the current cursor position, abbreviated if necessary. */ diff --git a/gdb/tui/tui-regs.c b/gdb/tui/tui-regs.c index 504aed4b81f..f5c2ec1bb58 100644 --- a/gdb/tui/tui-regs.c +++ b/gdb/tui/tui-regs.c @@ -354,17 +354,7 @@ tui_data_window::first_data_item_displayed () void tui_data_window::erase_data_content () { - werase (handle.get ()); - check_and_display_highlight_if_needed (); - - const char *prompt = _("[ Register Values Unavailable ]"); - int half_width = (width - box_size ()) / 2; - int x_pos; - if (strlen (prompt) >= half_width) - x_pos = 1; - else - x_pos = half_width - strlen (prompt); - display_string (height / 2, x_pos, prompt); + center_string (_("[ Register Values Unavailable ]")); } /* See tui-regs.h. */ diff --git a/gdb/tui/tui-winsource.c b/gdb/tui/tui-winsource.c index 2631714f248..6b8716cd27c 100644 --- a/gdb/tui/tui-winsource.c +++ b/gdb/tui/tui-winsource.c @@ -222,23 +222,9 @@ tui_update_source_windows_with_line (struct symtab_and_line sal) void tui_source_window_base::do_erase_source_content (const char *str) { - int x_pos; - int half_width = (width - box_size ()) / 2; - m_content.clear (); - if (handle != NULL) - { - werase (handle.get ()); - check_and_display_highlight_if_needed (); - - if (strlen (str) >= half_width) - x_pos = 1; - else - x_pos = half_width - strlen (str); - display_string (height / 2, x_pos, str); - - refresh_window (); - } + if (handle != nullptr) + center_string (str); } /* See tui-winsource.h. */ @@ -714,7 +700,7 @@ tui_source_window_base::update_exec_info (bool refresh_p) if (src_element->is_exec_point) element[TUI_EXEC_POS] = '>'; - display_string (i + box_width (), box_width (), element); + mvwaddstr (handle.get (), i + box_width (), box_width (), element); show_line_number (i); }