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 595C715806E for ; Wed, 7 Jun 2023 11:13:40 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 5EC80E0882; Wed, 7 Jun 2023 11:13:39 +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 3E207E0882 for ; Wed, 7 Jun 2023 11:13:39 +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 3501C340D3C for ; Wed, 7 Jun 2023 11:13:38 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id 901C1A8B for ; Wed, 7 Jun 2023 11:13:36 +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: <1686136338.b7245f936e1cd16aad6d9c7481fd0b52b2371703.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: b7245f936e1cd16aad6d9c7481fd0b52b2371703 X-VCS-Branch: master Date: Wed, 7 Jun 2023 11:13:36 +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: eaf28a3d-a4f7-4330-8b36-45b2d81ae667 X-Archives-Hash: eeb62d770dfbe6cf591fd2892ce164f3 commit: b7245f936e1cd16aad6d9c7481fd0b52b2371703 Author: Kerin Millar plushkava net> AuthorDate: Sat Feb 25 00:55:20 2023 +0000 Commit: Sam James gentoo org> CommitDate: Wed Jun 7 11:12:18 2023 +0000 URL: https://gitweb.gentoo.org/proj/gentoo-functions.git/commit/?id=b7245f93 Add and integrate the _update_winsize() function This new function assumes responsibility for updating the genfun_cols variable. Additionally, it assumes responsibility for updating the newly introduced genfun_rows variable. As before, stty(1) is used to determine the dimensions of the terminal. The approach has been slightly altered so as to incur just one subshell in the course of doing so. The reason for this is that changes will soon be made to the _eprint() and _eend() functions that require for the function to be called repeatedly, not merely at the time of sourcing functions.sh. Should stty(1) fail - or produce nonsensical output - it will no longer be assumed that there are 80 available columns. The requirement for the "[ ok ]" and "[ !! ]" indicators to always be indented was recently eliminated, so there is no longer any need to falsify a value for genfun_cols. Signed-off-by: Kerin Millar plushkava.net> Signed-off-by: Sam James gentoo.org> functions.sh | 42 ++++++++++++++++++------------------------ 1 file changed, 18 insertions(+), 24 deletions(-) diff --git a/functions.sh b/functions.sh index 44a6dce..c326af4 100644 --- a/functions.sh +++ b/functions.sh @@ -477,6 +477,23 @@ _ends_with_newline() { ! case $1 in *"${genfun_newline}") false ;; esac } +_update_winsize() { + # The following use of stty(1) is portable as of POSIX Issue 8. It would + # be beneficial to leverage the checkwinsize option in bash but the + # implementation is buggy. Given that Chet has agreed to investigate, + # it may eventually become possible to support it. + # shellcheck disable=2046 + set -- $(stty size 2>/dev/null) + if is_int "$1" && is_int "$2" && [ "$1" -gt 0 ] && [ "$2" -gt 0 ]; then + genfun_rows=$1 + genfun_cols=$2 + else + genfun_rows= + genfun_cols= + false + fi +} + # This is the main script, please add all functions above this point! # shellcheck disable=2034 RC_GOT_FUNCTIONS="yes" @@ -511,30 +528,7 @@ else done fi -# Try to determine the number of available columns in the terminal. -for _ in 1 2; do - case $_ in - 1) - # This use of stty(1) is portable as of POSIX Issue 8. - genfun_cols=$( - stty size 2>/dev/null | { - if IFS=' ' read -r _ cols; then - printf '%s\n' "${cols}" - fi - } - ) - ;; - 2) - # Give up and assume 80 available columns. - genfun_cols=80 - break - esac - if is_int "${genfun_cols}" && [ "${genfun_cols}" -gt 0 ]; then - break - fi -done - -if _has_dumb_terminal; then +if _has_dumb_terminal || ! _update_winsize; then unset -v genfun_endcol else # Set some ECMA-48 CSI sequences (CUU and CUF) for cursor positioning.