gbranden pushed a commit to branch master
in repository groff.

commit 396f6eb9d170d7d2426dc9ad281bea70740066c2
Author: G. Branden Robinson <[email protected]>
AuthorDate: Sun Nov 22 04:13:23 2026 -0600

    [grotty]: Recognize "TERM=dumb".
    
    * src/devices/grotty/tty.cpp (configure_plain_text_output): New function
      sets Booleans as the options `-cboOu` would.
    
      (main): Call this function if the environment variable `TERM` equals
      `dumb`.
    
    * src/devices/grotty/grotty.1.man (Environment): Document it.
    
    * src/devices/grotty/tests/TERM-equals-dumb-in-environment-works.sh:
    * src/devices/grotty/grotty.am: Test it.
    
    Fixes <https://savannah.gnu.org/bugs/?67947>.
    
    NEWS: Add item.
---
 ChangeLog                                          | 17 +++++++++++++++
 NEWS                                               |  5 +++++
 src/devices/grotty/grotty.1.man                    | 12 +++++++++++
 src/devices/grotty/grotty.am                       |  1 +
 .../tests/TERM-equals-dumb-in-environment-works.sh | 24 ++++++++++++++++++++++
 src/devices/grotty/tty.cpp                         | 15 ++++++++++++++
 6 files changed, 74 insertions(+)

diff --git a/ChangeLog b/ChangeLog
index e14ebab6f..9a00d288a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,20 @@
+2026-11-22  G. Branden Robinson <[email protected]>
+
+       [grotty]: Recognize "TERM=dumb".
+
+       * src/devices/grotty/tty.cpp (configure_plain_text_output): New
+       function sets Booleans as the options `-cboOu` would.
+       (main): Call this function if the environment variable `TERM`
+       equals `dumb`.
+
+       * src/devices/grotty/grotty.1.man (Environment): Document it.
+
+       * src/devices/grotty/tests/\
+       TERM-equals-dumb-in-environment-works.sh:
+       * src/devices/grotty/grotty.am: Test it.
+
+       Fixes <https://savannah.gnu.org/bugs/?67947>.
+
 2026-11-22  G. Branden Robinson <[email protected]>
 
        [grotty]: Implement `-O` option to suppress operation of groff's
diff --git a/NEWS b/NEWS
index 048c28805..0e2d60946 100644
--- a/NEWS
+++ b/NEWS
@@ -68,6 +68,11 @@ Output drivers
    overstriking sequences nor ISO 6429 escape sequences appear in its
    output.
 
+*  grotty now checks the process environment for the variable `TERM`; if
+   it is set to "dumb", the program configures itself as if the options
+   `-cboOu` had been specified, producing plain text output as described
+   in the previous item.
+
 
 VERSION 1.25.0
 ==============
diff --git a/src/devices/grotty/grotty.1.man b/src/devices/grotty/grotty.1.man
index c8ca08dbd..ad7a5f329 100644
--- a/src/devices/grotty/grotty.1.man
+++ b/src/devices/grotty/grotty.1.man
@@ -677,6 +677,18 @@ option were specified;
 see subsection \[lq]Legacy output format\[rq] above.
 .
 .
+.TP
+.I TERM
+If set to
+.RB \[lq] dumb \[rq],
+.I grotty
+behaves as if the options
+.B \-cboOu
+are specified,
+producing plain text output;
+it produces neither SGR/OSC nor overstriking sequences.
+.
+.
 .br
 .ne 3v \" Keep section heading and paragraph tag together.
 .\" ====================================================================
diff --git a/src/devices/grotty/grotty.am b/src/devices/grotty/grotty.am
index 3da08a882..4319addc6 100644
--- a/src/devices/grotty/grotty.am
+++ b/src/devices/grotty/grotty.am
@@ -35,6 +35,7 @@ EXTRA_DIST += \
 
 grotty_TESTS = \
   src/devices/grotty/tests/O-option-works.sh \
+  src/devices/grotty/tests/TERM-equals-dumb-in-environment-works.sh \
   src/devices/grotty/tests/basic-latin-glyphs-map-correctly.sh \
   src/devices/grotty/tests/continuous-underlining-works.sh \
   src/devices/grotty/tests/do-not-segv-on-huge-vertical-motion.sh \
diff --git a/src/devices/grotty/tests/TERM-equals-dumb-in-environment-works.sh 
b/src/devices/grotty/tests/TERM-equals-dumb-in-environment-works.sh
new file mode 100755
index 000000000..485b0eeb4
--- /dev/null
+++ b/src/devices/grotty/tests/TERM-equals-dumb-in-environment-works.sh
@@ -0,0 +1,24 @@
+#!/bin/sh
+#
+# This file is part of groff, the GNU roff typesetting system.
+#
+# groff 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.
+#
+# groff 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/>.
+
+groff="${abs_top_builddir:-.}/test-groff"
+
+output=$(TERM=dumb "$groff" -m an -T ascii src/devices/grotty/grotty.1)
+printf "%s\n" "$output"
+! printf "%s\n" "$output" | grep -E '[[:cntrl:]]'
+
+# vim:set autoindent expandtab shiftwidth=4 tabstop=4 textwidth=72:
diff --git a/src/devices/grotty/tty.cpp b/src/devices/grotty/tty.cpp
index 7538cc01a..15133bc4c 100644
--- a/src/devices/grotty/tty.cpp
+++ b/src/devices/grotty/tty.cpp
@@ -1047,12 +1047,27 @@ static void update_options()
   }
 }
 
+// equivalent to `-cboOu`
+static void configure_plain_text_output()
+{
+  use_overstriking_drawing_scheme = true; // meaning: not SGR
+  // Now shut off all the ways overstriking can happen.
+  want_emboldening_by_overstriking = false;
+  want_glyph_composition_by_overstriking = false;
+  want_continuous_underlining = false;
+  want_italics_by_underlining = false;
+}
+
 int main(int argc, char **argv)
 {
   program_name = argv[0];
   static char stderr_buf[BUFSIZ];
   if (getenv("GROFF_NO_SGR") != 0 /* nullptr */)
     use_overstriking_drawing_scheme = true;
+  const char *terminal_type = getenv("TERM");
+  if ((terminal_type != 0 /* nullptr */)
+      && (strcmp(terminal_type, "dumb") == 0))
+    configure_plain_text_output();
   setbuf(stderr, stderr_buf);
   setlocale(LC_CTYPE, "");
   int c;

_______________________________________________
groff-commit mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/groff-commit

Reply via email to