commit:     b86f278da7389b6a9e70cccb0bee831a53d50b83
Author:     Kerin Millar <kfm <AT> plushkava <DOT> net>
AuthorDate: Thu Feb 16 13:57:54 2023 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Fri Feb 17 01:33:09 2023 +0000
URL:        
https://gitweb.gentoo.org/proj/gentoo-functions.git/commit/?id=b86f278d

Don't assume that tput supports the cuu1 and cuf operands and will succeed

POSIX only guarantees for tput(1) to support the clear, init and reset
operands. Further, while the ncurses implementation supports many more,
it is foolhardy to assume that any given invocation of tput(1) will
succeed, let alone both. To remedy this, check the exit status of both
invocations and, should either fail, fall back to the method of directly
defining the (standard) ECMA-48 CSI sequences.

Signed-off-by: Kerin Millar <kfm <AT> plushkava.net>
Signed-off-by: Sam James <sam <AT> gentoo.org>

 functions.sh | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/functions.sh b/functions.sh
index 6523fa8..22e6ef9 100644
--- a/functions.sh
+++ b/functions.sh
@@ -488,7 +488,7 @@ for arg in "$@" ; do
        esac
 done
 
-# Define genfun_cols and genfun_endcol so that eend can line up the [ ok ].
+# Try to determine the number of available columns in the terminal.
 # shellcheck disable=3044
 if [ -n "${BASH}" ] && shopt -s checkwinsize 2>/dev/null; then
        # As is documented, running an external command will cause bash to set
@@ -516,11 +516,12 @@ else
        fi
 fi
 
-if hash tput 2>/dev/null; then
-       genfun_endcol="$(tput cuu1)$(tput cuf $(( genfun_cols - 8 )) )"
-else
-       genfun_endcol="$(printf '\033[A\033[%dC' "$(( genfun_cols - 8 ))")"
-fi
+# Set an ECMA-48 CSI sequence, allowing for eend to line up the [ ok ] string.
+{
+       genfun_endcol="$(tput cuu1)" \
+       && genfun_endcol="${genfun_endcol}$(tput cuf -- "$(( genfun_cols - 8 
))")" \
+       || genfun_endcol="$(printf '\033[A\033[%dC' "$(( genfun_cols - 8 ))")"
+} 2>/dev/null
 
 # Setup the colors so our messages all look pretty
 if yesno "${RC_NOCOLOR}"; then

Reply via email to