+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.
# - 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=
# 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():
# 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 }
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']