public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Tom de Vries <tdevries@suse.de>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tom@tromey.com>
Subject: [PATCH 3/6] [gdb/contrib] Add ansi-for-tui.sh
Date: Mon, 22 May 2023 15:15:42 +0200	[thread overview]
Message-ID: <20230522131545.12291-5-tdevries@suse.de> (raw)
In-Reply-To: <20230522131545.12291-1-tdevries@suse.de>

Using TUI with native TERM=xterm on an xterm:
...
$ TERM=xterm gdb -q -tui
...
works fine:
...
┌──────────────────────────────────────┐
│                                      │
│                                      │
│[ No Source Available ]               │
│                                      │
│                                      │
└──────────────────────────────────────┘
In:                        L??   PC: ??
(gdb)
...

However, in the testsuite we use tuiterm with native TERM=ansi.

We'd like to use an xterm to replay scenario's that are exercised in the
testsuite, and vice versa create scenario's on an xterm and be able to
reproduce those in the testsuite.  In order to ensure identical behaviour,
we'd need identical TERM settings.  So, can we use TERM=ansi on an xterm?

Using TERM=ansi is supported on xterm, with two documented caveats [1]:
- using the Alternative Character Set is broken, and
- you'd occasionally need to repaint the screen to work around the fact that
  xterm has the newline glitch (xenl capability), but by using TERM=ansi you
  indicate it hasn't.

When using TUI on an xterm with TERM=ansi we immediately run into both
problems:
...
ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
³                                      ³
³                                      ³
³[ No Source Available ]               ³
³                                      ³
³                                      ³
ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
In:                        L??   PC: ??(
gdb)
...
The border looks weird due to the problems with the ACS (PR tui/30370), and
the first char of the prompt ends up in the status line due the xenl
incompatibility (PR tui/30388).  As advertised, after doing ^L the latter
problem is solved, but not the former one.

Add a gdb/contrib script that can be used to generate a terminfo entry that
is based on the ansi terminfo entry but works around both of the problems, by:
- adding the xenl capability, and
- specifying ascii values for the hline, vline and border ACS chars, making
  tui border-kind acs equivalent to tui border-kind ascii.

I first used ansi-for-xterm as name, but found out that besides the
capabilities listed in the terminfo entry, ncurses also uses the name of the
terminal to decide whether to enable certain features, which consequently
requires more support in tuiterm.  So I chose ansi-for-tui instead.  It's also
more precise to use tui in the name because the ACS solution only supports
what TUI uses.

Tested on x86_64-linux, by checking that both problems are no longer
occurring:
...
+--------------------------------------+
|                                      |
|                                      |
|[ No Source Available ]               |
|                                      |
|                                      |
+--------------------------------------+
In:                        L??   PC: ??
(gdb)
...

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30370
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30388
---
 gdb/contrib/ansi-for-tui.sh | 66 +++++++++++++++++++++++++++++++++++++
 1 file changed, 66 insertions(+)
 create mode 100755 gdb/contrib/ansi-for-tui.sh

diff --git a/gdb/contrib/ansi-for-tui.sh b/gdb/contrib/ansi-for-tui.sh
new file mode 100755
index 00000000000..570ae3def81
--- /dev/null
+++ b/gdb/contrib/ansi-for-tui.sh
@@ -0,0 +1,66 @@
+#!/bin/bash
+
+# Copyright (C) 2023 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 <http://www.gnu.org/licenses/>.
+
+# Using TERM=ansi is supported on xterm, with two caveats [1]:
+# - using the Alternative Character Set is broken, and
+# - you'd occasionally need to repaint the screen to work around the fact that
+#   xterm has the newline glitch, but by using TERM=ansi you indicate it hasn't.
+# [1] http://man.he.net/man1/xterm
+#
+# This scripts addresses these two caveats by generating a new terminfo entry,
+# called ansi-for-tui, based on the ansi terminfo entry, with two
+# modifications:
+# - replace the acsc capability with a string that just uses ascii chars, and
+# - add the xenl capability.
+#
+# By default, it generates an entry in $HOME/.terminfo/a/ansi-for-tui.
+
+# This allows us to run TUI using "TERM=ansi-for-tui gdb -tui" on an xterm
+# and have things work as expected (just that tui border-kind acs and ascii
+# look the same).
+
+set -e
+
+base=ansi
+new=ansi-for-tui
+
+f=$(mktemp)
+
+# Copy from $base.
+infocmp -1 $base \
+	> "$f"
+
+# Add xenl.
+echo -e "\txenl," \
+     >> "$f"
+
+# Rename.
+sed -i "s/^$base/$new/" \
+    "$f"
+
+# Erase acsc line.
+sed -i "s/^\tacsc=.*$//" \
+    "$f"
+
+# Make acs hline, vline and corners fall back to ascii.
+echo -e "\tacsc=q-x|l+k+m+j+," \
+     >> "$f"
+
+# Compile.
+tic "$@" \
+    "$f"
+
+rm -f "$f"
-- 
2.35.3


  parent reply	other threads:[~2023-05-22 13:15 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-22 13:15 [PATCH 0/6] [gdb/tui] Introduce ansi-for-tui Tom de Vries
2023-05-22 13:15 ` [PATCH 1/6] [gdb/testsuite] Use TERM=dummy in gdb.tui/tuiterm.exp Tom de Vries
2023-05-22 13:15 ` [PATCH] [gdb/tui] Add set style tui-status-window Tom de Vries
2023-05-22 13:47   ` Eli Zaretskii
2023-05-22 14:22     ` Tom de Vries
2023-05-22 15:50       ` Eli Zaretskii
2023-05-22 13:15 ` [PATCH 2/6] [gdb/testsuite] Factor out Term::_wrap_cursor Tom de Vries
2023-05-22 13:15 ` Tom de Vries [this message]
2023-05-22 13:15 ` [PATCH 4/6] [gdb/testsuite] Make ansi-for-tui available in with_tuiterm Tom de Vries
2023-05-22 13:15 ` [PATCH 5/6] [gdb/testsuite] Implement the newline glitch in tuiterm Tom de Vries
2023-05-22 13:15 ` [PATCH 6/6] [gdb/testsuite] Use ansi-for-tui " Tom de Vries

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230522131545.12291-5-tdevries@suse.de \
    --to=tdevries@suse.de \
    --cc=gdb-patches@sourceware.org \
    --cc=tom@tromey.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).