doc: use TERM=dumb rather than HELP_NO_MARKUP to disable markup

This is a more standard mechanism to disable markup.

* src/system.h (oputs_): Logic change to honor TERM=dumb,
rather than HELP_NO_MARKUP=something.
* doc/coreutils.texi: Adjust the description for --help.
* man/local.mk: Ensure TERM is set to something,
so that man pages have links included.
* man/viewman: Just honor users $TERM.
* tests/misc/getopt_vs_usage.sh: Remove env var complication,
as TERM is unset automatically.
* tests/misc/usage_vs_refs.sh: Likewise.
* NEWS: Adjust the change in behavior note.
This commit is contained in:
Pádraig Brady 2026-01-22 11:42:47 +00:00
parent bdc45990c7
commit 87219034b7
7 changed files with 19 additions and 12 deletions

2
NEWS
View File

@ -70,7 +70,7 @@ GNU coreutils NEWS -*- outline -*-
with bold attributes, and hyperlinks into the online manual on gnu.org. with bold attributes, and hyperlinks into the online manual on gnu.org.
The links can be configured with the --enable-manual-url configure option, The links can be configured with the --enable-manual-url configure option,
and the bold highlighting with --disable-bold-man-page-references. and the bold highlighting with --disable-bold-man-page-references.
At runtime all markup can be disabled by setting the HELP_NO_MARKUP env var. At runtime all markup can be disabled by with the TERM=dumb env var value.
'fmt' -w,--width no longer includes '\n' in the width of a line. 'fmt' -w,--width no longer includes '\n' in the width of a line.
I.e., the specified width is interpreted to be an _inclusive_ maximum. I.e., the specified width is interpreted to be an _inclusive_ maximum.

View File

@ -764,12 +764,12 @@ these programs, abbreviations of the long options are not always recognized.
@item --help @item --help
@opindex --help @opindex --help
@vindex HELP_NO_MARKUP @vindex TERM
@cindex help, online @cindex help, online
Print a usage message listing all available options, then exit successfully. Print a usage message listing all available options, then exit successfully.
Help output may be marked up with terminal codes for formatting or Help output may be marked up with terminal codes for formatting or
hyperlinks, which can be disabled by setting the @env{HELP_NO_MARKUP} hyperlinks, which can be disabled by unsetting the @env{TERM} environment
environment variable. variable, or setting it to the value @samp{dumb}.
@item --version @item --version
@opindex --version @opindex --version

View File

@ -27,7 +27,8 @@ if HAVE_PERL
if BOLD_MAN_REFS if BOLD_MAN_REFS
help2man_OPTS=--bold-refs help2man_OPTS=--bold-refs
endif endif
run_help2man = $(PERL) -- $(srcdir)/man/help2man --loose-indent $(help2man_OPTS) run_help2man = env TERM=not_dumb $(PERL) -- \
$(srcdir)/man/help2man --loose-indent $(help2man_OPTS)
else else
run_help2man = $(SHELL) $(srcdir)/man/dummy-man run_help2man = $(SHELL) $(srcdir)/man/dummy-man
endif endif

View File

@ -8,7 +8,6 @@
# export MANPAGER=less # export MANPAGER=less
unset GROFF_NO_SGR unset GROFF_NO_SGR
unset HELP_NO_MARKUP
hdir=$(dirname "$0") hdir=$(dirname "$0")

View File

@ -542,7 +542,7 @@ is_nul (void const *buf, size_t length)
/* Output --option descriptions; /* Output --option descriptions;
formatted with ANSI format and hyperlink codes. formatted with ANSI format and hyperlink codes.
Any postprocessors like help2man etc. are expected to handle this, Any postprocessors like help2man etc. are expected to handle this,
though it can be disabled in edge cases with the HELP_NO_MARKUP env var. */ though it can be disabled in edge cases with the TERM=dumb env var. */
#define oputs(option) oputs_ (PROGRAM_NAME, option) #define oputs(option) oputs_ (PROGRAM_NAME, option)
static inline void static inline void
@ -554,13 +554,20 @@ oputs_ (MAYBE_UNUSED char const* program, char const *option)
#else #else
-1; /* Lookup. */ -1; /* Lookup. */
#endif #endif
if (help_no_sgr == 1 if (help_no_sgr == -1)
|| (help_no_sgr == -1 && (help_no_sgr = !!getenv ("HELP_NO_MARKUP")))) {
/* Note we don't consult isatty() since usually you
would want markup when piping to grep/less etc. */
char const *term = getenv ("TERM");
help_no_sgr = (!term || !*term || streq (term, "dumb"));
}
if (help_no_sgr)
{ {
fputs (option, stdout); fputs (option, stdout);
return; return;
} }
char const* first_word = option + strspn (option, " \t\n"); char const* first_word = option + strspn (option, " \t\n");
char const *option_text = strchr (option, '-'); char const *option_text = strchr (option, '-');
if (!option_text) if (!option_text)

View File

@ -44,12 +44,12 @@ for prg in $built_programs; do
got_option=false got_option=false
for opt in $(shortopts $sprg); do for opt in $(shortopts $sprg); do
got_option=true got_option=true
env HELP_NO_MARKUP=1 $prg --help | grep -F -- " -$opt" >/dev/null || env $prg --help | grep -F -- " -$opt" >/dev/null ||
{ printf -- '%s -%s missing from --help\n' $sprg $opt >&2; fail=1; } { printf -- '%s -%s missing from --help\n' $sprg $opt >&2; fail=1; }
done done
for opt in $(longopts $sprg); do for opt in $(longopts $sprg); do
got_option=true got_option=true
env HELP_NO_MARKUP=1 $prg --help | grep -F -- "--$opt" >/dev/null || env $prg --help | grep -F -- "--$opt" >/dev/null ||
{ printf -- '%s --%s missing from --help\n' $sprg $opt >&2; fail=1; } { printf -- '%s --%s missing from --help\n' $sprg $opt >&2; fail=1; }
done done
test "$DEBUG" && test $got_option = false && echo No options for $prg ? test "$DEBUG" && test $got_option = false && echo No options for $prg ?

View File

@ -25,7 +25,7 @@ longopts() { getopts $1 | cut -s -d'"' -f2; }
getopts() { getopts() {
skip='--help|--version' # These refs treated specially skip='--help|--version' # These refs treated specially
HELP_NO_MARKUP=1 env "$1" --help | env "$1" --help |
grep -E '^( -| --)' | # find options grep -E '^( -| --)' | # find options
grep -Ev -- " - |-M.*from first" | # exclude invalid matches grep -Ev -- " - |-M.*from first" | # exclude invalid matches
sed -e 's/^ *//' -e's/ .*//' | # strip leading space and descriptions sed -e 's/^ *//' -e's/ .*//' | # strip leading space and descriptions