]> git.ipfire.org Git - thirdparty/gnulib.git/commitdiff
gnulib-tool: Use bold output on Linux, NetBSD, OpenBSD, OmniOS consoles.
authorBruno Haible <bruno@clisp.org>
Fri, 29 Mar 2024 21:48:37 +0000 (22:48 +0100)
committerBruno Haible <bruno@clisp.org>
Fri, 29 Mar 2024 21:51:56 +0000 (22:51 +0100)
Reported by Pádraig Brady in
<https://lists.gnu.org/archive/html/bug-gnulib/2024-03/msg00399.html>.

* gnulib-tool.sh (func_show_module_list): Use 'tput' to determine the
"bold" capability of terminal types other than xterm*.
* pygnulib/constants.py (get_terminfo_string, bold_escapes): New
functions.
* pygnulib/GLTestDir.py (GLTestDir.execute): Invoke
constants.bold_escapes.
* pygnulib/GLImport.py (GLImport.prepare): Likewise.

ChangeLog
gnulib-tool.sh
pygnulib/GLImport.py
pygnulib/GLTestDir.py
pygnulib/constants.py

index 931322915b6de7296e753b08b5116dfde5b1b01c..6440b3d11fd6d42114ca91fe0ce1ed855779e4ba 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2024-03-29  Bruno Haible  <bruno@clisp.org>
+
+       gnulib-tool: Use bold output on Linux, NetBSD, OpenBSD, OmniOS consoles.
+       Reported by Pádraig Brady in
+       <https://lists.gnu.org/archive/html/bug-gnulib/2024-03/msg00399.html>.
+       * gnulib-tool.sh (func_show_module_list): Use 'tput' to determine the
+       "bold" capability of terminal types other than xterm*.
+       * pygnulib/constants.py (get_terminfo_string, bold_escapes): New
+       functions.
+       * pygnulib/GLTestDir.py (GLTestDir.execute): Invoke
+       constants.bold_escapes.
+       * pygnulib/GLImport.py (GLImport.prepare): Likewise.
+
 2024-03-29  Collin Funk  <collin.funk1@gmail.com>
 
        gnulib-tool.py: Display specified modules in bold.
index e0c8cfafbd4316402d2adb17aff3a9c4282b1854..6b12542adc817194d994c77925a07614be0121a0 100755 (executable)
@@ -3260,13 +3260,30 @@ func_modules_transitive_closure ()
 # - tmp             pathname of a temporary directory
 func_show_module_list ()
 {
-  if case "$TERM" in
-       xterm*) test -t 1;;
-       *) false;;
-     esac; then
-    # Assume xterm compatible escape sequences.
-    bold_on=`printf '\033[1m'`
-    bold_off=`printf '\033[0m'`
+  if test -n "$TERM" && test -t 1; then
+    case "$TERM" in
+      xterm*)
+        # Assume xterm compatible escape sequences.
+        bold_on=`printf '\033[1m'`
+        bold_off=`printf '\033[0m'`
+        ;;
+      *)
+        # Use the terminfo capability strings for "bold" and "sgr0".
+        if test "$TERM" = sun-color && test "`tput smso`" != "`tput rev`"; then
+          # Solaris 11 OmniOS: `tput smso` renders as bold,
+          #                    `tput rmso` is the same as `tput sgr0`.
+          bold_on=`tput smso 2>/dev/null`
+          bold_off=`tput rmso 2>/dev/null`
+        else
+          bold_on=`tput bold 2>/dev/null`
+          bold_off=`tput sgr0 2>/dev/null`
+        fi
+        if test -z "$bold_on" || test -z "$bold_off"; then
+          bold_on=
+          bold_off=
+        fi
+        ;;
+    esac
   else
     bold_on=
     bold_off=
index 84e1c08689b9e0761b4e59c731aa54ebc551cb2c..eb382cadac2c13808c5e2a2d640e6c410b932af5 100644 (file)
@@ -847,12 +847,7 @@ AC_DEFUN([%s_FILE_LIST], [\n''' % macro_prefix
 
         # Show final module list.
         if verbose >= 0:
-            bold_on = ''
-            bold_off = ''
-            term = os.getenv('TERM', '')
-            if term.startswith('xterm') and os.isatty(1):
-                bold_on = '\033[1m'
-                bold_off = '\033[0m'
+            (bold_on, bold_off) = constants.bold_escapes()
             print('Module list with included dependencies (indented):')
             for module in final_modules:
                 if str(module) in self.config.getModules():
index e395090b83a5a17ff0cb36e2b3ac17535c8a86a4..2a39eb3c5d1a3a91f7c3eda520e2967e4c335754 100644 (file)
@@ -258,12 +258,7 @@ class GLTestDir(object):
 
         # Show final module list.
         if verbose >= 0:
-            bold_on = ''
-            bold_off = ''
-            term = os.getenv('TERM', '')
-            if term.startswith('xterm') and os.isatty(1):
-                bold_on = '\033[1m'
-                bold_off = '\033[0m'
+            (bold_on, bold_off) = constants.bold_escapes()
             print('Module list with included dependencies (indented):')
             specified_modules_set = { str(module)
                                       for module in specified_modules }
index 16a60d1d3d970c428f9fa24c605c27982adb05cc..a6ef32cb47e7b85c3102bba327fa146df7df879e 100644 (file)
@@ -568,4 +568,42 @@ def combine_lines_matching(pattern: re.Pattern, text: str) -> str:
     return text
 
 
+def get_terminfo_string(capability: str) -> str:
+    '''Returns the value of a string-type terminfo capability for the current value of $TERM.
+    Returns the empty string if not defined.'''
+    value = ''
+    try:
+        value = sp.run(['tput', capability], stdout=sp.PIPE, stderr=sp.DEVNULL).stdout.decode('utf-8')
+    except Exception:
+        pass
+    return value
+
+
+def bold_escapes() -> tuple[str, str]:
+    '''Returns the escape sequences for turning bold-face on and off.'''
+    term = os.getenv('TERM', '')
+    if term != '' and os.isatty(1):
+        if term.startswith('xterm'):
+            # Assume xterm compatible escape sequences.
+            bold_on = '\033[1m'
+            bold_off = '\033[0m'
+        else:
+            # Use the terminfo capability strings for "bold" and "sgr0".
+            if term == 'sun-color' and get_terminfo_string('smso') != get_terminfo_string('rev'):
+                # Solaris 11 OmniOS: `tput smso` renders as bold,
+                #                    `tput rmso` is the same as `tput sgr0`.
+                bold_on = get_terminfo_string('smso')
+                bold_off = get_terminfo_string('rmso')
+            else:
+                bold_on = get_terminfo_string('bold')
+                bold_off = get_terminfo_string('sgr0')
+            if bold_on == '' or bold_off == '':
+                bold_on = ''
+                bold_off = ''
+    else:
+        bold_on = ''
+        bold_off = ''
+    return (bold_on, bold_off)
+
+
 __all__ += ['APP', 'DIRS', 'MODES', 'UTILS']