From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id 209CD15800F for ; Fri, 17 Feb 2023 01:33:43 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 4873CE0839; Fri, 17 Feb 2023 01:33:42 +0000 (UTC) Received: from smtp.gentoo.org (woodpecker.gentoo.org [140.211.166.183]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 21BA7E0839 for ; Fri, 17 Feb 2023 01:33:42 +0000 (UTC) Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id C632B341147 for ; Fri, 17 Feb 2023 01:33:40 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id 3BB108B3 for ; Fri, 17 Feb 2023 01:33:39 +0000 (UTC) From: "Sam James" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Sam James" Message-ID: <1676597589.b86f278da7389b6a9e70cccb0bee831a53d50b83.sam@gentoo> Subject: [gentoo-commits] proj/gentoo-functions:master commit in: / X-VCS-Repository: proj/gentoo-functions X-VCS-Files: functions.sh X-VCS-Directories: / X-VCS-Committer: sam X-VCS-Committer-Name: Sam James X-VCS-Revision: b86f278da7389b6a9e70cccb0bee831a53d50b83 X-VCS-Branch: master Date: Fri, 17 Feb 2023 01:33:39 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-Archives-Salt: cbd5b5b2-33d1-4067-a46b-576033cdb0fa X-Archives-Hash: 49aa8704e6198ef311eb799d77a6d76b commit: b86f278da7389b6a9e70cccb0bee831a53d50b83 Author: Kerin Millar plushkava net> AuthorDate: Thu Feb 16 13:57:54 2023 +0000 Commit: Sam James gentoo 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 plushkava.net> Signed-off-by: Sam James 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